This question already has an answer here:
- how to get class instance of generics type T 11 answers
I have following method and want to access Class object of generic T class such as String.class
, I mean why T.class
does not give class object.
public class GenericClass<T>{
public void map(T object){
//Field[] fields = T.class.getFields(); // not corrent statement
Field[] fields = object.getClass().getFields();
}
}
Aucun commentaire:
Enregistrer un commentaire