mardi 7 février 2017

How to get a typed object from passed type parameter in java generics

I want to pass in the class of the object (full class name), and generate a generic object of type which is passed in.

void foo(String className) {
LinkedList<className> listOfPassedType = new LinkedList<>();
// do other processing
}

So the question is how to create a generic object from the passed in type of classname.





Aucun commentaire:

Enregistrer un commentaire