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是真的。

  • 相关阅读:
    51nod 1102 面积最大的矩形 (单调栈)
    Loj 6280 数列分块入门 4
    Loj 6279 数列分块入门 3
    python 自己写package 导入 attempted relative import beyond top-level package
    Python __pycache__ 含义
    Hive 中 null 和N 的处理
    【shell】 shell 敏捷开发
    RPC 讲解
    neo4j 应用
    【Linux】 查看CPU占用
  • 原文地址:https://www.cnblogs.com/kino/p/9022339.html
Copyright © 2011-2022 走看看