A guide on using Device Classes as Functional Items
Non-Parameterized Device Classes access
When using the non-parameterized Device Class access, a compile warning will occur.
private ServiceTracker<MultiLevelControl, MultiLevelControl> track;
...
this.track = new ServiceTracker<MultiLevelControl, MultiLevelControl>(context, MultiLevelControl.class, null);
...
final MultiLevelControl tmc = this.track.getService();
// compile warning, MultiLevelControl is a raw type and should be parametrized.
Parameterized Device Classes access
Parameterized Device Classes access is possible with precautions:
Class<MultiLevelControl<Temperature>> tmpClz = (Class) MultiLevelControl.class;
...
ServiceTracker<MultiLevelControl<Temperature>, MultiLevelControl<Temperature>> track;
...
track = new ServiceTracker<MultiLevelControl<Temperature>, MultiLevelControl<Temperature>>(bc, tmpClz, null);
...
final MultiLevelControl<Temperature> tmc = track.getService();
Functional Items Interface
The Functional Item interface information is available with a cast. MultiLevelControl does not extend the Functional Item interface, but the service implementation does.
final MultiLevelControl<Temperature> tmc = this.track.getService();
FunctionalItem fi = (FunctionalItem) tmc;
System.out.println("Functional item UID '" + fi.getUID() + "'");
System.out.println("Functional item name '" + fi.getName() + "'");