java.lang.reflect - AccessibleObject Class


Advertisements


Introduction

The java.lang.reflect.AccessibleObject class is the base class for Field, Method and Constructor objects. It provides the ability to flag a reflected object as suppressing default Java language access control checks when it is used. The access checks for public, default (package) access, protected, and private members are performed when Fields, Methods or Constructors are used to set or get fields, to invoke methods, or to create and initialize new instances of classes, respectively. Setting the accessible flag in a reflected object permits sophisticated applications with sufficient privilege, such as Java Object Serialization or other persistence mechanisms, to manipulate objects in a manner that would normally be prohibited.

Class declaration

Following is the declaration for java.lang.reflect.AccessibleObject class −

public class AccessibleObject
   extends Object
      implements AnnotatedElement

Constructors

Sr.No. Constructor & Description
1 protected AccessibleObject()

Constructor: only used by the Java Virtual Machine.

Class methods

Sr.No. Method & Description
1 <T extends Annotation> T getAnnotation(Class<T> annotationClass)

Returns this element's annotation for the specified type if such an annotation is present, else null.

2 Annotation[] getAnnotations()

Returns all annotations present on this element.

3 Annotation[] getDeclaredAnnotations()

Returns all annotations that are directly present on this element.

4 boolean isAccessible()

Get the value of the accessible flag for this object.

5 boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)

Returns true if an annotation for the specified type is present on this element, else false.

6 static void setAccessible(AccessibleObject[] array, boolean flag)

Convenience method to set the accessible flag for an array of objects with a single security check (for efficiency).

7 void setAccessible(boolean flag)

Set the accessible flag for this object to the indicated boolean value.

Methods inherited

This class inherits methods from the following classes −

  • java.lang.Object


Advertisements
E-Books Store