mercredi 27 juillet 2016

java reflection field type before upcasting

I have simple class

public class SomeService {

    private Number number = new Integer(0);
}

Is it possible to find out by means of java reflection the field type before upcasting?

I can just obtain Number type instead of Integer:

      Field field = MealService.class.getDeclaredField("number");    
      field.setAccessible(true);
      System.out.println("impl:"+field.getType());

Please advice.





Aucun commentaire:

Enregistrer un commentaire