AnnotatedElement

public interface AnnotatedElement
Known Indirect Subclasses

Represents an annotated element of the program currently running in this VM. This interface allows annotations to be read reflectively. All annotations returned by methods in this interface are immutable and serializable. The arrays returned by methods of this interface may be modified by callers without affecting the arrays returned to other callers.

Android note: methods that return multiple annotations of different types such as getAnnotations() and getDeclaredAnnotations() can be affected by the explicit character-code ordering of annotations types specified by the DEX format. Annotations of different types on a single element are not guaranteed to be returned in the order they are declared in source.

The getAnnotationsByType(Class) and getDeclaredAnnotationsByType(Class) methods support multiple annotations of the same type on an element. If the argument to either method is a repeatable annotation type (JLS 9.6), then the method will "look through" a container annotation (JLS 9.7), if present, and return any annotations inside the container. Container annotations may be generated at compile-time to wrap multiple annotations of the argument type.

The terms directly present, indirectly present, present, and associated are used throughout this interface to describe precisely which annotations are returned by methods:

  • An annotation A is directly present on an element E if E is annotated by A in the original source.
  • An annotation A is indirectly present on an element E if E is annotated by a container annotation of A.
  • An annotation A is present on an element E if either:
    • A is directly present on E; or
    • No annotation of A 's type is directly present on E, and E is a class, and A 's type is inheritable, and A is present on the superclass of E.
  • An annotation A is associated with an element E if either:
    • A is directly or indirectly present on E; or
    • No annotation of A 's type is directly or indirectly present on E, and E is a class, and A's type is inheritable, and A is associated with the superclass of E.

The table below summarizes which kind of annotation presence different methods in this interface examine.

Overview of kind of presence de