lundi 28 août 2017

How to dynamically determine the Class a List must contains

I wrote this generic method, but I don't know how to programmatically tell the List the kind of objects it must contain.

I read that I can't know the <T> object class, so I added another parameter (returnClass) to the method.

public <T extends IModel> List<T> getIModel(Cursor cursor, Class<T> returnClass){

   //returnClass is the class that List must contains.

   //I need something like this
   List<returnClass.getClass()> list;     

}





Aucun commentaire:

Enregistrer un commentaire