Sample test case:
//Annotation with _ as one of the elements
@interface MyAnno {
int _() default 0;
}
// Element Value pair
@MyAnno(_=2)
class test{}
Compilation output:
test.java:3: warning: '_' used as an identifier
int _() default 0;
^
(use of '_' as an identifier might not be supported in future releases)
test.java:6: warning: '_' used as an identifier
@MyAnno(_=2)
^
(use of '_' as an identifier might not be supported in future releases)
test.java:6: error: ')' expected
@MyAnno(_=2)
^
test.java:6: error: class, interface, or enum expected
@MyAnno(_=2)
^
test.java:6: error: class, interface, or enum expected
@MyAnno(_=2)
^
3 errors
2 warnings
Errors in the above output are unexpected.
JLS rule in section 9.6 states the following:
AnnotationTypeElementDeclaration:
AbstractMethodModifiersopt Type Identifier ( ) DefaultValueopt ;