词条 | AccessibleObject |
释义 | public class AccessibleObjectextends Objectimplements AnnotatedElementAccessibleObject 类是 Field、Method 和 Constructor 对象的基类。它提供了将反射的对象标记为在使用时取消默认 Java 语言访问控制检查的能力。对于公共成员、默认(打包)访问成员、受保护成员和私有成员,在分别使用 Field、Method 或 Constructor 对象来设置或获得字段、调用方法,或者创建和初始化类的新实例的时候,会执行访问检查。 构造方法摘要(Annotation[] getAnnotations() boolean isAccessible() void setAccessible(boolean flag)) AccessibleObject(setAccessible isAccessible getAnnotation isAnnotationPresent getAnnotation getDeclaredAnnotation) java.lang.reflect 类 AccessibleObject java.lang.Object java.lang.reflect.AccessibleObject 所有已实现的接口: AnnotatedElement 直接已知子类: Constructor, Field, Method 作用在反射对象中设置 accessible 标志允许具有足够特权的复杂应用程序(比如 Java Object Serialization 或其他持久性机制)以某种通常禁止使用的方式来操作对象。 从以下版本开始: 1.2 另请参见: Field, Method, Constructor, ReflectPermission 构造方法摘要protected AccessibleObject() 构造方法:仅供 Java 虚拟机使用。 方法摘要 <T extends Annotation> TgetAnnotation(Class<T> annotationClass) 如果存在该元素的指定类型的注释,则返回这些注释,否则返回 null。 Annotation[] getAnnotations()返回此元素上存在的所有注释。Annotation[] getDeclaredAnnotations() 返回直接存在于此元素上的所有注释。 boolean isAccessible()获得此对象的 accessible 标志的值。 boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) 如果指定类型的注释存在于此元素上,则返回 true,否则返回 false。 static void setAccessible(AccessibleObject[] array, boolean flag) 使用单一安全性检查(为了提高效率)为一组对象设置 accessible 标志的便捷方法。 void setAccessible(boolean flag)将此对象的 accessible 标志设置为指示的布尔值。 从类 java.lang.Object 继承的方法 clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 构造方法详细信息 AccessibleObjectprotected AccessibleObject()构造方法:仅供 Java 虚拟机使用。 方法详细信息 setAccessiblepublic static void setAccessible(AccessibleObject[] array, boolean flag) throws SecurityException使用单一安全性检查(为了提高效率)为一组对象设置 accessible 标志的便捷方法。 首先,如果存在安全管理器,则在 ReflectPermission("suppressAccessChecks") 权限下调用 checkPermission 方法。 如果 flag 为 true,但是不能更改输入 array 的任何元素的可访问性(例如,如果元素对象是 Class 类的 Constructor 对象),则会引发 SecurityException。如果发生 SecurityException,对于少于(不包括)发生异常的元素的数组元素,可以将对象的可访问性设置为 flag;对于超出(包括)引发异常的元素的那些元素,则不更改其可访问性。 参数: array - AccessibleObjects 的数组 flag - 每个对象中的 accessible 标志的新值 抛出: SecurityException - 如果请求被拒绝。 另请参见: SecurityManager.checkPermission(java.security.Permission), RuntimePermission isAccessiblepublic boolean isAccessible()获得此对象的 accessible 标志的值。 返回: 此对象的 accessible 标志的值。 getAnnotationpublic <T extends Annotation> T getAnnotation(Class<T> annotationClass)从接口 AnnotatedElement 复制的描述 如果存在该元素的指定类型的注释,则返回这些注释,否则返回 null。 指定者: 接口 AnnotatedElement 中的 getAnnotation 参数: annotationClass - 对应于注释类型的 Class 对象 返回: 如果该元素的指定注释类型的注释存在于此对象上,则返回这些注释,否则返回 null isAnnotationPresentpublic boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)从接口 AnnotatedElement 复制的描述 如果指定类型的注释存在于此元素上,则返回 true,否则返回 false。此方法主要是为了便于访问标记注释而设计的。 指定者: 接口 AnnotatedElement 中的 isAnnotationPresent 参数: annotationClass - 对应于注释类型的 Class 对象 返回: 如果指定注释类型的注释存在于此对象上,则返回 true,否则返回 false getAnnotationpublic Annotation[] getAnnotations()从接口 AnnotatedElement 复制的描述 返回此元素上存在的所有注释。(如果此元素没有注释,则返回长度为零的数组。)该方法的调用方可以随意修改返回的数组;这不会对其他调用方返回的数组产生任何影响。 指定者: 接口 AnnotatedElement 中的 getAnnotations 返回: 此元素上存在的所有注释 getDeclaredAnnotationpublic Annotation[] getDeclaredAnnotations()从接口 AnnotatedElement 复制的描述 返回直接存在于此元素上的所有注释。与此接口中的其他方法不同,该方法将忽略继承的注释。(如果没有注释直接存在于此元素上,则返回长度为零的一个数组。)该方法的调用方可以随意修改返回的数组;这不会对其他调用方返回的数组产生任何影响。 指定者: 接口 AnnotatedElement 中的 getDeclaredAnnotations 返回: 直接存在于此元素上的所有注释 |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。