java获取对象所有属性_获取一个 Object 对象的所有属性

Field[] fields = xxxx.class.getDeclaredFields();  // 获取实体类的所有属性,返回Field数组

fields[0].setAccessible(true );

field.getName();  // 获取字段名称

field.get("fieldName");  // 获取字段值

注:

1、setAccessible:

Set the accessible flag for this object to the indicated boolean value. A value of true indicates that the reflected object should suppress Java language access checking when it is used. A value of false indicates that the reflected object should enforce Java language access checks.

First, if there is a security manager, its checkPermission method is called with a ReflectPermission("suppressAccessChecks") permission.

A SecurityException is raised if flag is true but accessibility of this object may not be changed (for example, if this element object is a Constructor object for the class Class).

A SecurityException is raised if this object is a Constructor object for the class java.lang.Class, and flag is true.

(

将此对象的可访问标志设置为指示布尔值。true的值表示反射对象在使用Java语言访问检查时应该抑制它。false表示反射的对象应该强制执行Java语言访问检查。

首先,如果有一个安全管理器,那么它的checkPermission方法就会被调用,并获得一个ReflectPermission(“抑制处理”)权限。

如果标记为true,则会抛出SecurityException,但是这个对象的可访问性可能不会被更改(例如,如果这个元素对象是类类的构造函数对象)。

如果该对象是类java.lang的构造函数对象,则会引发SecurityException。Class和flag是真的。

)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值