类: Integer id;
反射时:
Field f = User.class.getDeclaredField("id"); f.setAccessible(true); int s = f.getInt(u);
这样会报错:
java.lang.IllegalArgumentException: Attempt to get java.lang.Integer field "..." with illegal data type conversion to int
改为:
int s = (Integer) f.get(u);