< prev index next >

src/java.base/share/classes/java/lang/annotation/ElementType.java

Print this page




  29  * The constants of this enumerated type provide a simple classification of the
  30  * syntactic locations where annotations may appear in a Java program. These
  31  * constants are used in {@link Target java.lang.annotation.Target}
  32  * meta-annotations to specify where it is legal to write annotations of a
  33  * given type.
  34  *
  35  * <p>The syntactic locations where annotations may appear are split into
  36  * <em>declaration contexts</em> , where annotations apply to declarations, and
  37  * <em>type contexts</em> , where annotations apply to types used in
  38  * declarations and expressions.
  39  *
  40  * <p>The constants {@link #ANNOTATION_TYPE} , {@link #CONSTRUCTOR} , {@link
  41  * #FIELD} , {@link #LOCAL_VARIABLE} , {@link #METHOD} , {@link #PACKAGE} ,
  42  * {@link #PARAMETER} , {@link #TYPE} , and {@link #TYPE_PARAMETER} correspond
  43  * to the declaration contexts in JLS 9.6.4.1.
  44  *
  45  * <p>For example, an annotation whose type is meta-annotated with
  46  * {@code @Target(ElementType.FIELD)} may only be written as a modifier for a
  47  * field declaration.
  48  *
  49  * <p>The constant {@link #TYPE_USE} corresponds to the 15 type contexts in JLS
  50  * 4.11, as well as to two declaration contexts: type declarations (including
  51  * annotation type declarations) and type parameter declarations.
  52  *
  53  * <p>For example, an annotation whose type is meta-annotated with
  54  * {@code @Target(ElementType.TYPE_USE)} may be written on the type of a field
  55  * (or within the type of the field, if it is a nested, parameterized, or array
  56  * type), and may also appear as a modifier for, say, a class declaration.
  57  *
  58  * <p>The {@code TYPE_USE} constant includes type declarations and type
  59  * parameter declarations as a convenience for designers of type checkers which
  60  * give semantics to annotation types. For example, if the annotation type
  61  * {@code NonNull} is meta-annotated with
  62  * {@code @Target(ElementType.TYPE_USE)}, then {@code @NonNull}
  63  * {@code class C {...}} could be treated by a type checker as indicating that
  64  * all variables of class {@code C} are non-null, while still allowing
  65  * variables of other classes to be non-null or not non-null based on whether
  66  * {@code @NonNull} appears at the variable's declaration.
  67  *
  68  * @author  Joshua Bloch
  69  * @since 1.5




  29  * The constants of this enumerated type provide a simple classification of the
  30  * syntactic locations where annotations may appear in a Java program. These
  31  * constants are used in {@link Target java.lang.annotation.Target}
  32  * meta-annotations to specify where it is legal to write annotations of a
  33  * given type.
  34  *
  35  * <p>The syntactic locations where annotations may appear are split into
  36  * <em>declaration contexts</em> , where annotations apply to declarations, and
  37  * <em>type contexts</em> , where annotations apply to types used in
  38  * declarations and expressions.
  39  *
  40  * <p>The constants {@link #ANNOTATION_TYPE} , {@link #CONSTRUCTOR} , {@link
  41  * #FIELD} , {@link #LOCAL_VARIABLE} , {@link #METHOD} , {@link #PACKAGE} ,
  42  * {@link #PARAMETER} , {@link #TYPE} , and {@link #TYPE_PARAMETER} correspond
  43  * to the declaration contexts in JLS 9.6.4.1.
  44  *
  45  * <p>For example, an annotation whose type is meta-annotated with
  46  * {@code @Target(ElementType.FIELD)} may only be written as a modifier for a
  47  * field declaration.
  48  *
  49  * <p>The constant {@link #TYPE_USE} corresponds to the type contexts in JLS
  50  * 4.11, as well as to two declaration contexts: type declarations (including
  51  * annotation type declarations) and type parameter declarations.
  52  *
  53  * <p>For example, an annotation whose type is meta-annotated with
  54  * {@code @Target(ElementType.TYPE_USE)} may be written on the type of a field
  55  * (or within the type of the field, if it is a nested, parameterized, or array
  56  * type), and may also appear as a modifier for, say, a class declaration.
  57  *
  58  * <p>The {@code TYPE_USE} constant includes type declarations and type
  59  * parameter declarations as a convenience for designers of type checkers which
  60  * give semantics to annotation types. For example, if the annotation type
  61  * {@code NonNull} is meta-annotated with
  62  * {@code @Target(ElementType.TYPE_USE)}, then {@code @NonNull}
  63  * {@code class C {...}} could be treated by a type checker as indicating that
  64  * all variables of class {@code C} are non-null, while still allowing
  65  * variables of other classes to be non-null or not non-null based on whether
  66  * {@code @NonNull} appears at the variable's declaration.
  67  *
  68  * @author  Joshua Bloch
  69  * @since 1.5


< prev index next >