java reflection field type before upcasting
问题 I have a 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 advise. 回答1: field.getType() returns the declared type. If you want to know the instantiation type you have to first instantiate