Java Reference
In-Depth Information
By convention, the name of the sole element in a single-element annotation type is value .
Linguistic support for this convention is provided by the single element annotation con-
struct (ยง 9.7.3 ); one must obey the convention in order to take advantage of the construct.
Example 9.6.1-2. Single-Element Annotation Type Declarations
The convention is illustrated in the following annotation type declaration:
Click here to view code image
/**
* Associates a copyright notice with the annotated API element.
*/
@interface Copyright {
String value();
}
The following annotation type declaration defines a single-element annotation type
whose sole element has an array type:
Click here to view code image
/**
* Associates a list of endorsers with the annotated class.
*/
@interface Endorsers {
String[] value();
}
The following annotation type declaration shows a Class annotation whose value is re-
stricted by a bounded wildcard:
Click here to view code image
interface Formatter {}
// Designates a formatter to pretty-print the annotated class
@interface PrettyPrinter {
Class<? extends Formatter> value();
}
Note that the grammar for annotation type declarations permits other element declara-
tions besides method declarations. For example, one might choose to declare a nested
enum for use in conjunction with an annotation type:
Click here to view code image
@interface Quality {
enum Level { BAD, INDIFFERENT, GOOD }
Search WWH ::




Custom Search