Java Reference
In-Depth Information
It is a compile-time error if the element type is not commensurate with the
ElementValue
.
If the element type is not an annotation type or an array type,
ElementValue
must be a
ConditionalExpression
(§
15.25
).
A
ConditionalExpression
is simply an expression without assignments, and not neces-
sarily an expression involving the conditional operator (
? :
).
ConditionalExpression
is preferred over
Expression
in
ElementValue
because an element value has a simple
structure (constant expression or class literal or enum constant) that may easily be rep-
resented in binary form.
If the element type is an array type and the corresponding
ElementValue
is not an
Ele-
mentValueArrayInitializer
, then an array value whose sole element is the value represented
by the
ElementValue
is associated with the element. Otherwise, if the corresponding
Ele-
mentValue
is an
ElementValueArrayInitializer
, then the array value represented by the
Ele-
mentValueArrayInitializer
is associated with the element.
In other words, it is permissible to omit the curly braces when a single-element array
is to be associated with an array-valued annotation type element.
Note that the array's element type cannot be an array type. That is, nested array types
are not permitted as element types. (While the annotation syntax would permit this,
the annotation type declaration syntax would not.)
An
ElementValue
is always FP-strict (§
15.4
).
An annotation on an annotation type declaration is known as a
meta-annotation
.
An annotation type may be used to annotate its own declaration. More generally, circular-
ities in the transitive closure of the “annotates” relation are permitted.
For example, it is legal to annotate an annotation type declaration with another an-
notation type, and to annotate the latter type's declaration with the former type. (The
pre-defined meta-annotation types contain several such circularities.)
Example 9.7.1-1. Normal Annotations
Here is an example of a normal annotation.
@RequestForEnhancement(
id = 2868724,
synopsis = "Provide time-travel functionality",
engineer = "Mr. Peabody",