[type-annos-observers] error: enclosing static nested class cannot be annotated ??

Alex Buckley alex.buckley at oracle.com
Tue Oct 8 17:53:36 PDT 2013


Hi Werner,

On 10/7/2013 7:30 PM, Werner Dietl wrote:
> Put differently, it makes a difference whether the static class is on
> the left or right of the selection. It is OK if the left class is
> static; it is not OK for the right type to be static.

OK, got it. The trick is to focus very closely on the annotation and the 
two names immediately following it. The annotation and the two names may 
be at the "top level" of a type, such as "@Illegal Y.YY.Z", where an 
error occurs because YY is static in Y. Or the annotation and the type 
names may appear deep within a type, such as "Y. at Illegal YY.Z", where 
the annotation is in fact legal because Z is non-static in YY.

I will formulate this semantic constraint and a related one as follows:

-----
A type annotation is _admissible_ if both of the following hold:

- The simple name to which the annotation is closest is classified as a 
TypeName, not a PackageName.

- If the simple name to which the annotation is closest is followed by 
"." and another TypeName, i.e., the annotation appears as @X T.U, then U 
denotes an inner class of T.

It is a compile-time error if an annotation of type T applies to a type 
(or any part of a type) in a type context, and T is applicable in type 
contexts, and the annotation is not admissible.
-----

Alex


More information about the type-annotations-spec-observers mailing list