November 2004
Intermediate to advanced
1024 pages
27h 50m
English
In this section, we cover everything you need to know about the annotation syntax.
An annotation is defined by an annotation interface:
modifiers @interface AnnotationName{ element declaration1 element declaration2 . . .}
Each element declaration has the form
type elementName();
or
type elementName() default value;
For example, the following annotation has two elements, assignedTo and severity.
public @interface BugReport
{
String assignedTo() default "[none]";
int severity() = 0;
}
Each annotation has the format
@AnnotationName(elementName1=value1, elementName2=value2, . . .)
For example,
@BugReport(assignedTo="Harry", severity=10)
The order of the elements does not matter. The annotation
@BugReport(severity=10, ...
Read now
Unlock full access