類: 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);