I have the following problem: I have a class object(MyClass.class) and from that class object i need to instantiate an object.That is the easy part ois MyClass.class.getDeclaredConstructor().newInstance()
(the class has only one constructor which takes no arguments).
The tricky part(or so i think) is to cast the resulted object to the appropriate type(MyClass) using the class object with which i created. Note that i can't write the following code (MyClass)MyClass.class.getDeclaredConstructor().newInstance()
If someone can help me with this that would be much appreciated.
Aucun commentaire:
Enregistrer un commentaire