複製鏈接
請複製以下鏈接發送給好友

AccessibleObject

鎖定
public class AccessibleObjectextends Objectimplements AnnotatedElementAccessibleObject 類是 Field、Method 和 Constructor 對象的基類。它提供了將反射的對象標記為在使用時取消默認 Java 語言訪問控制檢查的能力。
對於公共成員、默認(打包)訪問成員、受保護成員和私有成員,在分別使用 Field、Method 或 Constructor 對象來設置或獲得字段、調用方法,或者創建和初始化類的新實例的時候,會執行訪問檢查。
中文名
AccessibleObject
正    文
java.lang.reflect
另請參見
Field, Method, Constructor,
構造方法摘要
protected AccessibleObject()

AccessibleObject類的結構

java.lang.Object
java.lang.reflect.AccessibleObject
所有已實現的接口:
直接已知子類:
Constructor, Field, Method

AccessibleObject主要作用

在反射對象中設置 accessible 標誌允許具有足夠特權的複雜應用程序(比如 Java Object Serialization 或其他持久性機制)以某種通常禁止使用的方式來操作對象。
從以下版本開始:
1.2
另請參見:
Field, Method, Constructor, ReflectPermission

AccessibleObject構造方法

protected AccessibleObject()
構造方法:僅供 Java虛擬機使用。
方法摘要
<T extends Annotation>
T
getAnnotation(Class<T> annotationClass)
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
構造方法詳細信息
產品説明
protected AccessibleObject()構造方法:僅供 Java 虛擬機使用。
方法詳細信息
setAccessible
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
isAccessible
public boolean isAccessible()獲得此對象的 accessible 標誌的值。
返回:
此對象的 accessible 標誌的值。
getAnnotation
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)從接口AnnotatedElement複製的描述
如果存在該元素的指定類型的註釋,則返回這些註釋,否則返回 null。
指定者:
接口AnnotatedElement中的 getAnnotation
參數:
annotationClass - 對應於註釋類型的 Class 對象
返回:
如果該元素的指定註釋類型的註釋存在於此對象上,則返回這些註釋,否則返回 null
isAnnotationPresent
此方法主要是為了便於訪問標記註釋而設計的。
指定者:
接口 AnnotatedElement 中的 isAnnotationPresent
參數:
annotationClass - 對應於註釋類型的 Class 對象
返回:
如果指定註釋類型的註釋存在於此對象上,則返回 true,否則返回 false
getAnnotations
public Annotation[] getAnnotations()從接口 AnnotatedElement 複製的描述
返回此元素上存在的所有註釋。(如果此元素沒有註釋,則返回長度為零的數組。)
指定者:
接口 AnnotatedElement 中的 getAnnotations
返回:
此元素上存在的所有註釋
getDeclaredAnnotations
public Annotation[] getDeclaredAnnotations()從接口 AnnotatedElement 複製的描述
返回直接存在於此元素上的所有註釋。與此接口中的其他方法不同,該方法將忽略繼承的註釋。(如果沒有註釋直接存在於此元素上,則返回長度為零的一個數組。)該方法的調用方可以隨意修改返回的數組;這不會對其他調用方返回的數組產生任何影響。
指定者:
接口 AnnotatedElement 中的 getDeclaredAnnotations
返回:
直接存在於此元素上的所有註釋