Some final spec errata (ArrayType, AnnotationTypeElementDeclaration)
Alex Buckley
alex.buckley at oracle.com
Fri Feb 14 18:34:54 PST 2014
I received a private mail from a reader of the JLS8 draft, noting that
the ArrayType and UnannArrayType productions show the square brackets to
be optional:
ArrayType:
PrimitiveType {{Annotation} [ ]}
ClassOrInterfaceType {{Annotation} [ ]}
TypeVariable {{Annotation} [ ]}
This error, which makes the grammar ambiguous, has existed since the
preview of Public Review in October 2013. Happily, implementations do
the right thing.
Separately, I realized that JLS8 wrongly disallows annotations in an
element of an annotation type declaration, on the legacy [] part:
AnnotationTypeElementDeclaration:
{AnnotationTypeElementModifier} UnannType Identifier ( ) {[ ]}
[DefaultValue] ;
Because elements are really method declarations, and because method
declarations allow annotations on a legacy [], javac allows annotations
on the legacy [] in an element. (The rules of annotation types actually
allow only one level of brackets here, despite the grammar allowing more.)
It is too late to correct the JLS in the Final Release of JSR 337 (Java
SE 8), but the printed book and docs.oracle.com material will say:
ArrayType:
PrimitiveType Dims
ClassOrInterfaceType Dims
TypeVariable Dims
Dims:
{Annotation} [ ] {{Annotation} [ ]}
AnnotationTypeElementDeclaration:
{AnnotationTypeElementModifier} UnannType Identifier ( ) [Dims]
[DefaultValue] ;
Alex
More information about the type-annotations-spec-experts
mailing list