Java Reference
In-Depth Information
9.7.3. Single-Element Annotations
The third form of annotation,
single-element annotation
, is a shorthand designed for use
with single-element annotation types.
SingleElementAnnotation:
@
Identifier
(
ElementValue
)
It is shorthand for the normal annotation:
@Identifier(value = ElementValue)
It is legal to use single-element annotations for annotation types with multiple elements, so
long as one element is named
value
, and all other elements have default values.
Example 9.7.3-1. Single-Element Annotations
Here is an example of a single-element annotation.
@Copyright("2002 Yoyodyne Propulsion Systems, Inc.")
public class OscillationOverthruster { ... }
Here is an example of an array-valued single-element annotation.
@Endorsers({"Children", "Unscrupulous dentists"})
public class Lollipop { ... }
Here is an example of a single-element array-valued single-element annotation. Note
that the curly braces are omitted.
@Endorsers("Epicurus")
public class Pleasure { ... }
Here is an example with of a single-element annotation that contains a normal annota-
tion.
@Author(@Name(first = "Joe", last = "Hacker"))
public class BitTwiddle { ... }
Here is an example of a single-element annotation with a
Class
element whose value is
restricted by the use of a bounded wildcard.