lundi 23 novembre 2015

getDeclaredFields with actual runtime type, Java reflection

getDeclaredFields[0].getType() is returning only the compile time class info. I have following code, where java.lang.reflect.Field's type is expected with actual type.

public class Wrapper {
     final private Object field1;
      //getters and setters for field1 and constructor
}
class SomeClass {

}
Wrapper wrapper = new Wrapper();
wrapper.field1 = new SomeClass();
System.out.println(wrapper.getType().getDeclaredFields[0].getType());

I am asking this weird requirement, because the serliaztion library I am integrating expects java.lang.reflect.Field





Aucun commentaire:

Enregistrer un commentaire