ElementType | API reference | Android Developers (original) (raw)
Summary:Enums | Methods | Inherited Methods
public final enum ElementType` extends [Enum](/reference/java/lang/Enum)<[ElementType](/reference/java/lang/annotation/ElementType)>`
The constants of this enumerated class provide a simple classification of the syntactic locations where annotations may appear in a Java program. These constants are used in [Target](/reference/java/lang/annotation/Target) meta-annotations to specify where it is legal to write annotations of a given type.
The syntactic locations where annotations may appear are split into_declaration contexts_, where annotations apply to declarations, and_type contexts_, where annotations apply to types used in declarations and expressions.
The constants [ANNOTATION_TYPE](/reference/java/lang/annotation/ElementType#ANNOTATION%5FTYPE), [CONSTRUCTOR](/reference/java/lang/annotation/ElementType#CONSTRUCTOR), [FIELD](/reference/java/lang/annotation/ElementType#FIELD), [LOCAL_VARIABLE](/reference/java/lang/annotation/ElementType#LOCAL%5FVARIABLE), [METHOD](/reference/java/lang/annotation/ElementType#METHOD), [PACKAGE](/reference/java/lang/annotation/ElementType#PACKAGE), [MODULE](/reference/java/lang/annotation/ElementType#MODULE), [PARAMETER](/reference/java/lang/annotation/ElementType#PARAMETER), [TYPE](/reference/java/lang/annotation/ElementType#TYPE), and [TYPE_PARAMETER](/reference/java/lang/annotation/ElementType#TYPE%5FPARAMETER) correspond to the declaration contexts in JLS 9.6.4.1.
For example, an annotation whose interface is meta-annotated with@Target(ElementType.FIELD) may only be written as a modifier for a field declaration.
The constant [TYPE_USE](/reference/java/lang/annotation/ElementType#TYPE%5FUSE) corresponds to the type contexts in JLS 4.11, as well as to two declaration contexts: class and interface declarations (including annotation declarations) and type parameter declarations.
For example, an annotation whose interface is meta-annotated with@Target(ElementType.TYPE_USE) may be written on the class or interface of a field (or within the class or interface of the field, if it is a nested or parameterized class or interface, or array class), and may also appear as a modifier for, say, a class declaration.
The TYPE_USE constant includes class and interface declarations and type parameter declarations as a convenience for designers of type checkers which give semantics to annotation interfaces. For example, if the annotation interface NonNull is meta-annotated with@Target(ElementType.TYPE_USE), then @NonNull class C {...} could be treated by a type checker as indicating that all variables of class C are non-null, while still allowing variables of other classes to be non-null or not non-null based on whether@NonNull appears at the variable's declaration.
Summary
| Enum values | |
|---|---|
| ElementType | ANNOTATION_TYPE Annotation interface declaration (Formerly known as an annotation type.) |
| ElementType | CONSTRUCTOR Constructor declaration |
| ElementType | FIELD Field declaration (includes enum constants) |
| ElementType | LOCAL_VARIABLE Local variable declaration |
| ElementType | METHOD Method declaration |
| ElementType | MODULE Module declaration. |
| ElementType | PACKAGE Package declaration |
| ElementType | PARAMETER Formal parameter declaration |
| ElementType | RECORD_COMPONENT Record component |
| ElementType | TYPE Class, interface (including annotation interface), enum, or record declaration |
| ElementType | TYPE_PARAMETER Type parameter declaration |
| ElementType | TYPE_USE Use of a type |
| Public methods | |
|---|---|
| staticElementType | valueOf(String name) |
| static finalElementType[] | values() |
| Inherited methods |
|---|
| From class java.lang.Enum finalObject clone() Throws CloneNotSupportedException. final int compareTo(E o) Compares this enum with the specified object for order. final boolean equals(Object other) Returns true if the specified object is equal to this enum constant. final void finalize() enum classes cannot have finalize methods. finalClass getDeclaringClass() Returns the Class object corresponding to this enum constant's enum type. final int hashCode() Returns a hash code for this enum constant. finalString name() Returns the name of this enum constant, exactly as declared in its enum declaration. final int ordinal() Returns the ordinal of this enumeration constant (its position in its enum declaration, where the initial constant is assigned an ordinal of zero). String toString() Returns the name of this enum constant, as contained in the declaration. static <T extends Enum> T valueOf(Class enumClass, String name) Returns the enum constant of the specified enum class with the specified name. |
| From class java.lang.Object Object clone() Creates and returns a copy of this object. boolean equals(Object obj) Indicates whether some other object is "equal to" this one. void finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. finalClass<?> getClass() Returns the runtime class of this Object. int hashCode() Returns a hash code value for the object. final void notify() Wakes up a single thread that is waiting on this object's monitor. final void notifyAll() Wakes up all threads that are waiting on this object's monitor. String toString() Returns a string representation of the object. final void wait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait() Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
| From interface java.lang.Comparable abstract int compareTo(E o) Compares this object with the specified object for order. |
Enum values
ANNOTATION_TYPE
public static final ElementType ANNOTATION_TYPE
Annotation interface declaration (Formerly known as an annotation type.)
CONSTRUCTOR
public static final ElementType CONSTRUCTOR
Constructor declaration
FIELD
public static final ElementType FIELD
Field declaration (includes enum constants)
LOCAL_VARIABLE
public static final ElementType LOCAL_VARIABLE
Local variable declaration
METHOD
public static final ElementType METHOD
Method declaration
MODULE
public static final ElementType MODULE
Module declaration.
PACKAGE
public static final ElementType PACKAGE
Package declaration
PARAMETER
public static final ElementType PARAMETER
Formal parameter declaration
RECORD_COMPONENT
public static final ElementType RECORD_COMPONENT
Record component
TYPE
public static final ElementType TYPE
Class, interface (including annotation interface), enum, or record declaration
TYPE_PARAMETER
public static final ElementType TYPE_PARAMETER
Type parameter declaration
TYPE_USE
public static final ElementType TYPE_USE
Use of a type