In my code below I get the printer1 type as interface(IPrinter) type but i actually want it as printer class type.
In JavaReflectionTrial.accessPrinter() i have 2 give the Slot as parameter not the printer
is it possible to get printer in JavaReflectionTrial as Printer object.
interface IPrinter {
void enable();
}
class Printer implements Iprinter {
void enable() {
//doSomething;
}
}
class Slot {
public IPrinter printer1 = new Printer();
}
class JavaReflectionTrial {
accessPrinter(Slot slot) {
class cls=slot.getclass();
field[] fields=cls.getfields();
}
}
If you have a
Slotobject and through reflection you want to get at itsprinter1member variable, you should be able to do that like this: