java.lang.reflect.AccessibleObject
This class must be implemented by the VM vendor. This class is the superclass
of all member reflect classes (Field, Constructor, Method). AccessibleObject
provides the ability to toggle 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 applications such as Java
Object Serialization, inspectors, and debuggers to have complete access to
objects.
Known Direct Subclasses
Constructor<T> |
This class models a constructor. |
Field |
This class must be implemented by the VM vendor. |
Method |
This class models a method. |
Summary
Protected Constructors
Public Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Protected Constructors
protected
AccessibleObject()
AccessibleObject constructor. AccessibleObjects can only be created by
the Virtual Machine.
Public Methods
public
T
getAnnotation(Class<T> annotationType)
Gets the
Annotation for this element for the annotation type
passed, if it exists.
public
Annotation[]
getDeclaredAnnotations()
Gets all
Annotations that are explicitly declared by this
element (not inherited).
public
boolean
isAccessible()
Returns the value of the accessible flag. This is false if access checks
are performed, true if they are skipped.
Returns
- the value of the accessible flag
public
boolean
isAnnotationPresent(Class<? extends Annotation> annotationType)
Queries whether a given Annotation is present on the AccessibleObject.
Parameters
annotationType
| The type of Annotation to look for. |
Returns
- true if and only if the given Annotation is present.
public
void
setAccessible(boolean flag)
Attempts to set the value of the accessible flag. Setting this flag to
false will enable access checks, setting to true will disable them. If
there is a security manager, checkPermission is called with a
ReflectPermission("suppressAccessChecks").
Parameters
flag
| the new value for the accessible flag |
public
static
void
setAccessible(AccessibleObject[] objects, boolean flag)
Attempts to set the value of the accessible flag for all the objects in
the array provided. Only one security check is performed. Setting this
flag to false will enable access checks, setting to true will disable
them. If there is a security manager, checkPermission is called with a
ReflectPermission("suppressAccessChecks").
Parameters
objects
| the accessible objects |
flag
| the new value for the accessible flag |