Java Reference
In-Depth Information
Annotations must contain an element-value pair for every element of the corresponding an-
notation type, except for those elements with default values, or a compile-time error occurs.
Annotations may, but are not required to, contain element-value pairs for elements with de-
fault values.
Annotations may be used as modifiers in any declaration, whether package (§ 7.4.1 ) , class
8.1.1 ) (including enums (§ 8.9 )), interface (§ 9.1.1 ) (including annotation types (§ 9.6 ) ),
field (§ 8.3.1 , § 9.3 ) , method (§ 8.4.3 , § 9.4 ), formal parameter (§ 8.4.1 ) , constructor (§ 8.8.3 ) ,
or local variable (§ 14.4.1 ) .
Annotations may also be used on enum constants. Such annotations are placed immediately
before the enum constant they annotate.
It is a compile-time error if a declaration is annotated with more than one annotation for a
given annotation type.
Annotations are conventionally placed before all other modifiers, but this is not a re-
quirement; they may be freely intermixed with other modifiers.
Annotations:
Annotation
Annotations Annotation
Annotation:
NormalAnnotation
MarkerAnnotation
SingleElementAnnotation
There are three kinds of annotations. The first (normal annotation) is fully general. The
others (marker annotation and single-element annotation) are merely shorthands.
9.7.1. Normal Annotations
A normal annotation is used to annotate a program element.
NormalAnnotation:
@ TypeName ( ElementValuePairs opt )
ElementValuePairs:
ElementValuePair
ElementValuePairs , ElementValuePair
ElementValuePair:
Identifier = ElementValue
Search WWH ::




Custom Search