zoukankan      html  css  js  c++  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是真的。

  • 相关阅读:
    【PMP】商业论证与效益管理文件
    【PMP】项目生命周期和开发生命周期
    【PMP】组织级项目管理(OPM)和战略
    【PMP】项目和运营的区别
    【PMP】项目、项目集、项目组合
    【PMP】项目的定义和特点
    c++ 调用模板函数时加template什么意思?
    散列表
    Windows消息机制详解
    python 获取当前目录下文件(转)
  • 原文地址:https://www.cnblogs.com/kino/p/9022339.html
Copyright © 2011-2022 走看看