An annotation interface element may have a default value, specified by attaching the keyword default and a value to the method declaration which defines the element.
DefaultValue:
default ElementValue
The following productions from §9.7.1 are shown here for convenience:
ElementValue:
ConditionalExpression
ElementValueArrayInitializer
Annotation
ElementValueArrayInitializer:
{ [ElementValueList] [,] }
ElementValueList:
ElementValue {, ElementValue}
It is a compile-time error if the type of the element is not commensurate (§9.7) with the default value specified.
Default values are not compiled into annotations, but rather applied dynamically at the time annotations are read. Thus, changing a default value affects annotations even in classes that were compiled before the change was made (presuming these annotations lack an explicit value for the defaulted element).
Example 9.6.2-1. Annotation Interface Declaration With Default Values
Here is a refinement of the RequestForEnhancement annotation interface from §9.6.1:
@interface RequestForEnhancement {
int id(); // No default - must be specified in
// each annotation
String synopsis(); // No default - must be specified in
// each annotation
String engineer() default "[unassigned]";
String date() default "[unimplemented]";
}