jeudi 14 avril 2016

Java - Create a variable which does the same thing as a name of a class

Maybe the title souds misterious, but i don't the specific words of java. I will try to be clear :

I would like to create an instance of the class A<T extends B>, but I only know the Type of T.

Type myType = ...; //defined in my code via getGenericParameterTypes() from a Constructor object
Class myVariable = Class.forName(myType.getTypeName());
A<myVariable> = new A<myVariable>(); //doesn't work

Maybe some of you may know a solution or an other way to do it.

Thank you !





Aucun commentaire:

Enregistrer un commentaire