public class AccessibleObject extends Object implements AnnotatedElement
在一个体现对象允许复杂的应用程序具有足够的权限设置accessible
旗,如java对象序列化或其他持久性机制,操纵的方式,通常会被禁止的对象。
默认情况下,一个反射对象是不可访问的。
Field
,
方法
,
Constructor
,
ReflectPermission
Modifier | Constructor and Description |
---|---|
protected |
AccessibleObject()
构造函数:只有通过java虚拟机。
|
Modifier and Type | Method and Description |
---|---|
<T extends Annotation> |
getAnnotation(类<T> annotationClass)
如果存在此注释,则返回此元素的指定类型的注释,否则为空。
|
Annotation[] |
getAnnotations()
返回此元素上的注释。
|
<T extends Annotation> |
getAnnotationsByType(类<T> annotationClass)
返回与此元素关联的注释。
|
<T extends Annotation> |
getDeclaredAnnotation(类<T> annotationClass)
返回此元素的指定类型的注释,如果这样的注释是直接存在的,否则为空。
|
Annotation[] |
getDeclaredAnnotations()
返回直接在该元素上的注释。
|
<T extends Annotation> |
getDeclaredAnnotationsByType(类<T> annotationClass)
如果这样的注释直接存在或间接存在,则返回指定类型的该元素的注释(s)。
|
boolean |
isAccessible()
得到的
accessible 标志该对象的值。
|
boolean |
isAnnotationPresent(类<? extends Annotation> annotationClass)
如果在这个元素上存在指定类型的注释,则返回真,否则为假。
|
static void |
setAccessible(AccessibleObject[] array, boolean flag)
为一个单一的安全检查对象数组设置
accessible 方便旗的方法(效率)。
|
void |
setAccessible(boolean flag)
该对象到指定的布尔值设置
accessible 旗。
|
public static void setAccessible(AccessibleObject[] array, boolean flag) throws SecurityException
accessible
方便旗的方法(效率)。
首先,如果存在安全管理器,它的checkPermission
方法称为一个ReflectPermission("suppressAccessChecks")
许可。
如果一个SecurityException
flag
是true
但任何输入的array
元素可不能改变了(例如,如果元素对象是类的一个对象类
Constructor
)。在这样一个动态的事件,对象的可访问性设置为数组元素flag
至(不包括)的,发生异常元素;辅助元素以外的元素(包括),发生异常是不变的。
array
- accessibleobjects阵列
flag
为每个对象的
accessible
标志的新价值
SecurityException
如果请求被拒绝。
SecurityManager.checkPermission(java.security.Permission)
,
RuntimePermission
public void setAccessible(boolean flag) throws SecurityException
accessible
旗。一个价值
true
表明反射的对象应当压制java语言访问检查时。一个价值
false
表明反射的对象应该执行java语言访问检查。
首先,如果存在安全管理器,它的checkPermission
方法称为一个ReflectPermission("suppressAccessChecks")
许可。
如果一个SecurityException
flag
是true
但此对象的可访问性不会改变了(例如,如果该元素对象是类的一个对象类
Constructor
)。
如果这是一个SecurityException
对象是类java.lang.Class
一Constructor
对象提出的,并flag
是真实的。
flag
为
accessible
标志的新价值
SecurityException
如果请求被拒绝。
SecurityManager.checkPermission(java.security.Permission)
,
RuntimePermission
public boolean isAccessible()
accessible
标志该对象的值。
accessible
标志值
public <T extends Annotation> T getAnnotation(类<T> annotationClass)
AnnotatedElement
getAnnotation
接口
AnnotatedElement
T
-查询并返回如果目前的标注类型
annotationClass
-对应的注释类型的类对象
NullPointerException
如果注释类是无效的
public boolean isAnnotationPresent(类<? extends Annotation> annotationClass)
此方法返回的真实价值相当于:getAnnotation(annotationClass) != null
默认方法的主体被指定为上面的代码。
isAnnotationPresent
接口
AnnotatedElement
annotationClass
-对应的注释类型的类对象
NullPointerException
如果注释类是无效的
public <T extends Annotation> T[] getAnnotationsByType(类<T> annotationClass)
AnnotatedElement
AnnotatedElement.getAnnotation(Class)
之间的区别是,该方法检测如果它的参数是一个可重复的注释类型(年9.6),如果是这样的话,试图找到一个或更多的注释,通过“浏览”式容器标注。此方法的调用方可以自由修改返回的数组;它将对返回给其他调用方的数组没有影响。
getAnnotationsByType
接口
AnnotatedElement
T
-查询并返回如果目前的标注类型
annotationClass
-对应的注释类型的类对象
NullPointerException
如果注释类是无效的
public Annotation[] getAnnotations()
AnnotatedElement
getAnnotations
接口
AnnotatedElement
public <T extends Annotation> T getDeclaredAnnotation(类<T> annotationClass)
AnnotatedElement
getDeclaredAnnotation
接口
AnnotatedElement
T
-查询,如果直接提出返回的标注类型
annotationClass
-对应的注释类型的类对象
NullPointerException
如果注释类是无效的
public <T extends Annotation> T[] getDeclaredAnnotationsByType(类<T> annotationClass)
AnnotatedElement
AnnotatedElement.getDeclaredAnnotation(Class)
之间的区别是,该方法检测如果它的参数是一个可重复的注释类型(年9.6),如果是这样的话,试图找到一个或更多的注释,通过“浏览”式容器注释如果存在。此方法的调用方可以自由修改返回的数组;它将对返回给其他调用方的数组没有影响。
getDeclaredAnnotationsByType
接口
AnnotatedElement
T
-注释类型来查询并返回如果直接或间接存在
annotationClass
-对应的注释类型的类对象
NullPointerException
如果注释类是无效的
public Annotation[] getDeclaredAnnotations()
AnnotatedElement
getDeclaredAnnotations
接口
AnnotatedElement
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.