# AccessibleObject

public class **AccessibleObject** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
implements [AnnotatedElement](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AnnotatedElement.html)

|---|---|---|
| Known Direct Subclasses [Executable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Executable.html), [Field](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Field.html) |---|---| | [Executable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Executable.html) | A shared superclass for the common functionality of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Method.html` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Constructor.html`. | | [Field](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Field.html) | A `Field` provides information about, and dynamic access to, a single field of a class or an interface. | |||

|---|---|---|
| Known Indirect Subclasses [Constructor](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Constructor.html)\<T\>, [Method](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Method.html) |---|---| | [Constructor](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Constructor.html)\<T\> | `Constructor` provides information about, and access to, a single constructor for a class. | | [Method](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Method.html) | A `Method` provides information about, and access to, a single method on a class or interface. | |||

The 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.

By default, a reflected object is *not* accessible.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Field.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Method.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Constructor.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/ReflectPermission.html`

### Protected Constructor Summary

|---|---|
|   | [AccessibleObject](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AccessibleObject.html#AccessibleObject())() |

### Public Method Summary

|---|---|
| \<T extends [Annotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html)\> T | [getAnnotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AccessibleObject.html#getAnnotation(java.lang.Class<T>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> annotationClass) Returns this element's annotation for the specified type if such an annotation is *present*, else null. |
| [Annotation\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html) | [getAnnotations](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AccessibleObject.html#getAnnotations())() Returns annotations that are *present* on this element. |
| \<T extends [Annotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html)\> T\[\] | [getAnnotationsByType](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AccessibleObject.html#getAnnotationsByType(java.lang.Class<T>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> annotationClass) Returns annotations that are *associated* with this element. |
| \<T extends [Annotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html)\> T | [getDeclaredAnnotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AccessibleObject.html#getDeclaredAnnotation(java.lang.Class<T>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> annotationClass) Returns this element's annotation for the specified type if such an annotation is *directly present*, else null. |
| [Annotation\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html) | [getDeclaredAnnotations](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AccessibleObject.html#getDeclaredAnnotations())() Returns annotations that are *directly present* on this element. |
| \<T extends [Annotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html)\> T\[\] | [getDeclaredAnnotationsByType](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AccessibleObject.html#getDeclaredAnnotationsByType(java.lang.Class<T>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> annotationClass) Returns this element's annotation(s) for the specified type if such annotations are either *directly present* or *indirectly present*. |
| boolean | [isAccessible](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AccessibleObject.html#isAccessible())() Get the value of the `accessible` flag for this object. |
| boolean | [isAnnotationPresent](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AccessibleObject.html#isAnnotationPresent(java.lang.Class<?%20extends%20java.lang.annotation.Annotation>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<? extends [Annotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html)\> annotationClass) Returns true if an annotation for the specified type is *present* on this element, else false. |
| void | [setAccessible](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AccessibleObject.html#setAccessible(boolean))(boolean flag) Set the `accessible` flag for this object to the indicated boolean value. |
| static void | [setAccessible](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AccessibleObject.html#setAccessible(java.lang.reflect.AccessibleObject[],%20boolean))([AccessibleObject\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AccessibleObject.html) array, boolean flag) Convenience method to set the `accessible` flag for an array of objects with a single security check (for efficiency). |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.lang.reflect.AnnotatedElement](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AnnotatedElement.html)

|---|---|
| abstract \<T extends [Annotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html)\> T | [getAnnotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AnnotatedElement.html#getAnnotation(java.lang.Class<T>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> annotationClass) Returns this element's annotation for the specified type if such an annotation is *present*, else null. |
| abstract [Annotation\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html) | [getAnnotations](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AnnotatedElement.html#getAnnotations())() Returns annotations that are *present* on this element. |
| \<T extends [Annotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html)\> T\[\] | [getAnnotationsByType](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AnnotatedElement.html#getAnnotationsByType(java.lang.Class<T>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> annotationClass) Returns annotations that are *associated* with this element. |
| \<T extends [Annotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html)\> T | [getDeclaredAnnotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AnnotatedElement.html#getDeclaredAnnotation(java.lang.Class<T>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> annotationClass) Returns this element's annotation for the specified type if such an annotation is *directly present*, else null. |
| abstract [Annotation\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html) | [getDeclaredAnnotations](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AnnotatedElement.html#getDeclaredAnnotations())() Returns annotations that are *directly present* on this element. |
| \<T extends [Annotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html)\> T\[\] | [getDeclaredAnnotationsByType](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AnnotatedElement.html#getDeclaredAnnotationsByType(java.lang.Class<T>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> annotationClass) Returns this element's annotation(s) for the specified type if such annotations are either *directly present* or *indirectly present*. |
| boolean | [isAnnotationPresent](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AnnotatedElement.html#isAnnotationPresent(java.lang.Class<?%20extends%20java.lang.annotation.Annotation>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<? extends [Annotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html)\> annotationClass) Returns true if an annotation for the specified type is *present* on this element, else false. |

## Protected Constructors

#### protected
**AccessibleObject**
()

<br />

## Public Methods

#### public T
**getAnnotation**
([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> annotationClass)

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

##### Parameters

| annotationClass | the Class object corresponding to the annotation type |
|---|---|

##### Returns

- this element's annotation for the specified annotation type if present on this element, else null

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) |   |
|---|---|

#### public [Annotation\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html)
**getAnnotations**
()

Returns annotations that are *present* on this element.

If there are no annotations *present* on this element, the return
value is an array of length 0.

The caller of this method is free to modify the returned array; it will
have no effect on the arrays returned to other callers.

##### Returns

- annotations present on this element

#### public T\[\]
**getAnnotationsByType**
([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> annotationClass)

Returns annotations that are *associated* with this element.

If there are no annotations *associated* with this element, the return
value is an array of length 0.

The difference between this method and `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AnnotatedElement.html#getAnnotation(java.lang.Class<T>)`
is that this method detects if its argument is a *repeatable
annotation type* (JLS 9.6), and if so, attempts to find one or
more annotations of that type by "looking through" a container
annotation.

The caller of this method is free to modify the returned array; it will
have no effect on the arrays returned to other callers.

##### Parameters

| annotationClass | the Class object corresponding to the annotation type |
|---|---|

##### Returns

- all this element's annotations for the specified annotation type if associated with this element, else an array of length zero

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) |   |
|---|---|

#### public T
**getDeclaredAnnotation**
([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> annotationClass)

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

This method ignores inherited annotations. (Returns null if no
annotations are directly present on this element.)

##### Parameters

| annotationClass | the Class object corresponding to the annotation type |
|---|---|

##### Returns

- this element's annotation for the specified annotation type if directly present on this element, else null

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) |   |
|---|---|

#### public [Annotation\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html)
**getDeclaredAnnotations**
()

Returns annotations that are *directly present* on this element.
This method ignores inherited annotations.

If there are no annotations *directly present* on this element,
the return value is an array of length 0.

The caller of this method is free to modify the returned array; it will
have no effect on the arrays returned to other callers.

##### Returns

- annotations directly present on this element

#### public T\[\]
**getDeclaredAnnotationsByType**
([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<T\> annotationClass)

Returns this element's annotation(s) for the specified type if
such annotations are either *directly present* or
*indirectly present* . This method ignores inherited
annotations.

If there are no specified annotations directly or indirectly
present on this element, the return value is an array of length
0.

The difference between this method and `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AnnotatedElement.html#getDeclaredAnnotation(java.lang.Class<T>)` is that this method detects if its
argument is a *repeatable annotation type* (JLS 9.6), and if so,
attempts to find one or more annotations of that type by "looking
through" a container annotation if one is present.

The caller of this method is free to modify the returned array; it will
have no effect on the arrays returned to other callers.

##### Parameters

| annotationClass | the Class object corresponding to the annotation type |
|---|---|

##### Returns

- all this element's annotations for the specified annotation type if directly or indirectly present on this element, else an array of length zero

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) |   |
|---|---|

#### public boolean
**isAccessible**
()

Get the value of the `accessible` flag for this object.

##### Returns

- the value of the object's `accessible` flag

#### public boolean
**isAnnotationPresent**
([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<? extends [Annotation](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/annotation/Annotation.html)\> annotationClass)

Returns true if an annotation for the specified type
is *present* on this element, else false. This method
is designed primarily for convenient access to marker annotations.

The truth value returned by this method is equivalent to:
`getAnnotation(annotationClass) != null`

The body of the default method is specified to be the code
above.

##### Parameters

| annotationClass | the Class object corresponding to the annotation type |
|---|---|

##### Returns

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

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) |   |
|---|---|

#### public void
**setAccessible**
(boolean flag)

Set the `accessible` flag for this object to
the indicated boolean value. A value of `true` indicates that
the reflected object should suppress Java language access
checking when it is used. A value of `false` indicates
that the reflected object should enforce Java language access checks.

First, if there is a security manager, its
`checkPermission` method is called with a
`ReflectPermission("suppressAccessChecks")` permission.

A `SecurityException` is raised if `flag` is
`true` but accessibility of this object may not be changed
(for example, if this element object is a `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Constructor.html` object for
the class `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html`).

A `SecurityException` is raised if this object is a `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Constructor.html` object for the class
`java.lang.Class`, and `flag` is true.

##### Parameters

| flag | the new value for the `accessible` flag |
|---|---|

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if the request is denied. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkPermission(java.security.Permission)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/RuntimePermission.html`

#### public static void
**setAccessible**
([AccessibleObject\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/AccessibleObject.html) array, boolean flag)

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

First, if there is a security manager, its
`checkPermission` method is called with a
`ReflectPermission("suppressAccessChecks")` permission.

A `SecurityException` is raised if `flag` is
`true` but accessibility of any of the elements of the input
`array` may not be changed (for example, if the element
object is a `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/reflect/Constructor.html` object for the class `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html`). In the event of such a SecurityException, the
accessibility of objects is set to `flag` for array elements
upto (and excluding) the element for which the exception occurred; the
accessibility of elements beyond (and including) the element for which
the exception occurred is unchanged.

##### Parameters

| array | the array of AccessibleObjects |
| flag | the new value for the `accessible` flag in each object |
|---|---|

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if the request is denied. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkPermission(java.security.Permission)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/RuntimePermission.html`