Object对象如何类获取对应类的属性值
2016-12-19 11:02
495 查看
Object对象如何类获取对应类的属性值
public void test() throws NoSuchFieldException, IllegalAccessException { Deposit deposit=new Deposit(); deposit.setBusinessType("业务类型"); deposit.setDescription("业务描述"); Object object=deposit; Class<?> s=object.getClass(); System.out.println("类名"+s); for (Field f:object.getClass().getDeclaredFields()){ //遍历通过反射获取object的类中的属性名 f.setAccessible(true); //设置改变属性为可访问 if(f.getName().equals("businessType")){ System.out.println("属性值"+f.get(object)); } } 运行结果(成功获取object里的属性值):
注:
在运行的过程中有遇到有遇到一个问题,
报错:
can not access a member of class com.hc.apps.depositManage.entity.Deposit with modifiers “private”
解决方法:
加上 f.setAccessible(true);
相关文章推荐
- C#如何获取object对象的属性值
- C#如何获取object对象的属性值
- C#如何获取object对象的属性值
- C#如何获取object对象的属性值(type反射)
- js获取对象,数组所有属性值(key)和对应值(value)的方法
- js中如何复制一个对象并获取其所有属性和属性对应的值
- JAVA 反射获得object对象对应的实体类的属性、及属性值
- [置顶] js中如何复制一个对象,如何获取所有属性和属性对应的值
- js获取对象,数组所有属性值(key)和对应值(value)的方法
- 如何获取Agile PLM Business Object 对应Agile对象的属性?
- js中如何复制一个对象,如何获取所有属性和属性对应的值
- MongoDB在插入后,如何获取对应的ObjectId
- JAVA 反射获得object对象对应的实体类的属性、及属性值
- js中如何复制一个对象并获取其所有属性和属性对应的值
- js中如何复制一个对象,如何获取所有属性和属性对应的值
- Javascript获取对象的属性名及对应的属性值
- 10-10 arguments存储实参、解决js获取CSS属性值兼容性、object对象、for语句遍历对象内容、数组中的方法
- 如何用javascript获取文本框,下拉框,单选框的对应值或者将值赋给它们
- 如何获取GDI对象的属性信息
- 如何动态创建Control对象,并为其指定初始属性值