Name

AccessibleObject

Synopsis

This class is the superclass of the Method, Constructor, and Field classes; its methods provide a mechanism for trusted applications to work with private, protected, and default visibility members that would otherwise not be accessible through the Reflection API. This class is new as of Java 1.2; in Java 1.1, the Method, Constructor, and Field classes extended Object directly.

To use the java.lang.reflect package to access a member to which your code would not normally have access, pass true to the setAccessible( ) method. If your code has an appropriate ReflectPermission (such as “suppressAccessChecks”), this allows access to the member as if it were declared public. The static version of setAccessible( ) is a convenience method that sets the accessible flag for an array of members but performs only a single security check.

java.lang.reflect.AccessibleObject

Figure 10-91. java.lang.reflect.AccessibleObject

public class AccessibleObject implements AnnotatedElement {
// Protected Constructors
     protected AccessibleObject( );  
// Public Class Methods
     public static void setAccessible(AccessibleObject[ ] array, boolean flag) 
     throws SecurityException;  
// Public Instance Methods
     public boolean isAccessible( );  
     public void setAccessible(boolean flag) throws SecurityException;  
// Methods Implementing AnnotatedElement
                  5.0  public <T extends java.lang.annotation.Annotation> T getAnnotation(Class<T> ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.