- public static void getFieldDemo()throws Exception{
- String name="bean.Person";
- Class clazz=Class.forName(name);
- Field field=clazz.getDeclaredField("age");//只获取本类中的,但包括私有的
- Object obj=clazz.newInstance();
- field.setAccessable(true);
- field.set(obj,89);
- Object o=field.get(obj);
-
- System.out.println(o);
-
- }
复制代码 |
|