Java Reference
In-Depth Information
Note that the at-sign ( @ ) and the keyword interface are two distinct tokens. Technically
it is possible to separate them with whitespace, but this is discouraged as a matter of
style.
AnnotationTypeDeclaration:
InterfaceModifiers opt @ interface Identifier AnnotationTypeBody
AnnotationTypeBody:
{ AnnotationTypeElementDeclarations opt }
AnnotationTypeElementDeclarations:
AnnotationTypeElementDeclaration
AnnotationTypeElementDeclarations AnnotationTypeElementDeclaration
If an annotation a 9.7 ) on an annotation type declaration corresponds to an annotation
type T , and T has a (meta-)annotation m that corresponds to java.lang.annotation.Target , then
m must have either an element whose value is
java.lang.annotation.ElementType.ANNOTATION_TYPE , or an element whose value is
java.lang.annotation.ElementType.TYPE , or a compile-time error occurs.
The Identifier in an annotation type declaration specifies the name of the annotation type.
It is a compile-time error if an annotation type has the same simple name as any of its en-
closing classes or interfaces.
The direct superinterface of an annotation type is always java.lang.annotation.Annotation .
By virtue of the AnnotationTypeDeclaration syntax, an annotation type declaration
cannot be generic, and no extends clause is permitted.
A consequence of the fact that an annotation type cannot explicitly declare a super-
class or superinterface is that a subclass or subinterface of an annotation type is never
itself an annotation type. Similarly, java.lang.annotation.Annotation is not itself an annota-
tion type.
An annotation type declaration inherits several members from java.lang.annotation.Annotation ,
including the implicitly declared methods corresponding to the instance methods in Object ,
yet these methods do not define elements (§ 9.6.1 ) of the annotation type and it is illegal to
use them in annotations.
Without this rule, we could not ensure that the elements were of the types represent-
able in annotations, or that accessor methods for them would be available.
Unless explicitly modified herein, all of the rules that apply to ordinary interface declara-
tions apply to annotation type declarations.
Search WWH ::




Custom Search