public class AccessibleObject extends Object implements AnnotatedElement
AccessibleObject
is the superclass of all member reflection classes
(Field, Constructor, Method). AccessibleObject provides the ability to toggle
a flag controlling access checks for these objects. By default, accessing a
member (for example, setting a field or invoking a method) checks the
validity of the access (for example, invoking a private method from outside
the defining class is prohibited) and throws IllegalAccessException if the
operation is not permitted. If the accessible flag is set to true, these
checks are omitted. This allows privileged code, such as Java object
serialization, object inspectors, and debuggers to have complete access to
objects.Field
,
Constructor
,
Method
Modifier | Constructor and Description |
---|---|
protected |
AccessibleObject()
Constructs a new
AccessibleObject instance. |
Modifier and Type | Method and Description |
---|---|
<T extends Annotation> |
getAnnotation(Class<T> annotationType)
Returns, for this element, the annotation with the specified type, or
null if no annotation with the specified type is present
(including inherited annotations). |
Annotation[] |
getAnnotations()
Returns, for this element, an array containing all annotations (including
inherited annotations).
|
Annotation[] |
getDeclaredAnnotations()
Returns, for this element, all annotations that are explicitly declared
(not inherited).
|
boolean |
isAccessible()
Indicates whether this object is accessible without access checks being
performed.
|
boolean |
isAnnotationPresent(Class<? extends Annotation> annotationType)
Indicates whether or not this element has an annotation with the
specified annotation type (including inherited annotations).
|
static void |
setAccessible(AccessibleObject[] objects,
boolean flag)
Attempts to set the value of the accessible flag for all the objects in
the array provided.
|
void |
setAccessible(boolean flag)
Attempts to set the value of the accessible flag.
|
protected AccessibleObject()
AccessibleObject
instance. AccessibleObject
instances can only be constructed by the virtual
machine.public static void setAccessible(AccessibleObject[] objects, boolean flag)
false
will enable access checks, setting to true
will disable them.objects
- the accessible objectsflag
- the new value for the accessible flagsetAccessible(boolean)
public boolean isAccessible()
true
if this object is accessible without access
checks, false
otherwisepublic void setAccessible(boolean flag)
false
will enable access checks, setting to true
will
disable them.flag
- the new value for the accessible flagpublic boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
AnnotatedElement
isAnnotationPresent
in interface AnnotatedElement
annotationType
- the type of the annotation to search fortrue
if the annotation exists, false
otherwisepublic Annotation[] getDeclaredAnnotations()
AnnotatedElement
getDeclaredAnnotations
in interface AnnotatedElement
public Annotation[] getAnnotations()
AnnotatedElement
getAnnotations
in interface AnnotatedElement
public <T extends Annotation> T getAnnotation(Class<T> annotationType)
AnnotatedElement
null
if no annotation with the specified type is present
(including inherited annotations).getAnnotation
in interface AnnotatedElement
annotationType
- the type of the annotation to search fornull