java 反射获取属性值 方法
- public static void main(String[] args) throws SecurityException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException
- {
- TestEntity obj = new TestEntity();
- obj.setName("name value");
- obj.setCode("code value");
- Field[] fds = Class.forName
- ("com.test.impl.TestEntity").getDeclaredFields();
- System.out.println(fds.length);
- for(int i=0;i<fds.length;i++)
- {
- System.out.println(fds[i].get(obj));
- }
- }