Skip to content

Most visited

Recently visited

navigation
Added in API level 1

AccessibleObject

public class AccessibleObject
extends Object implements AnnotatedElement

java.lang.Object
   ↳ java.lang.reflect.AccessibleObject
Known Direct Subclasses


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.

See also:

Summary

Protected constructors

AccessibleObject()

Public methods

<T extends Annotation> T 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()

Returns true if this object is accessible without access checks.

boolean isAnnotationPresent(Class<? extends Annotation> annotationType)

Indicates whether or not this element has an annotation with the specified annotation type (including inherited annotations).

void setAccessible(boolean flag)

Attempts to set the accessible flag.

static void setAccessible(AccessibleObject[] objects, boolean flag)

Attempts to set the accessible flag for all objects in objects.

Inherited methods

From class java.lang.Object
From interface java.lang.reflect.AnnotatedElement

Protected constructors

AccessibleObject

Added in API level 1
AccessibleObject ()

Public methods

getAnnotation

Added in API level 1
T 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).

Parameters
annotationType Class: the type of the annotation to search for
Returns
T the annotation with the specified type or null

getAnnotations

Added in API level 1
Annotation[] getAnnotations ()

Returns, for this element, an array containing all annotations (including inherited annotations). If there are no annotations present, this method returns a zero length array.

Returns
Annotation[] an array of all annotations for this element

getDeclaredAnnotations

Added in API level 1
Annotation[] getDeclaredAnnotations ()

Returns, for this element, all annotations that are explicitly declared (not inherited). If there are no declared annotations present, this method returns a zero length array.

Returns
Annotation[] an array of annotations declared for this element

isAccessible

Added in API level 1
boolean isAccessible ()

Returns true if this object is accessible without access checks.

Returns
boolean

isAnnotationPresent

Added in API level 1
boolean isAnnotationPresent (Class<? extends Annotation> annotationType)

Indicates whether or not this element has an annotation with the specified annotation type (including inherited annotations).

Parameters
annotationType Class: the type of the annotation to search for
Returns
boolean true if the annotation exists, false otherwise

setAccessible

Added in API level 1
void setAccessible (boolean flag)

Attempts to set the accessible flag. Setting this to true prevents IllegalAccessExceptions.

Parameters
flag boolean

setAccessible

Added in API level 1
void setAccessible (AccessibleObject[] objects, 
                boolean flag)

Attempts to set the accessible flag for all objects in objects. Setting this to true prevents IllegalAccessExceptions.

Parameters
objects AccessibleObject
flag boolean
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.