[JSR308] Syntax of annotations on arrays

Michael Ernst mernst at csail.mit.edu
Tue Jan 30 19:54:33 EST 2007

>   The prosed syntax is suggesting to introduce array annotations like this:
>   Document[][@Readonly] docs5 = new Document[2][@Readonly 12];
>   The problem I see with this syntax is that it may interfere with the 
> expression used for array dimensions. Java language currently allow to 
> write something like this:
>   int n;
>   Document[] d = new Document[n = 5];
>   and we may end up with something like new Document[@Readonly n = 5], 
> which doesn't seem allow to identify if annotation belong to the array 
> element or to the expression defining its index or dimensions.

At present, the proposal does not permit an annotation to be directly
attached to an arbitrary expression.  Therefore, in the above it is clear
that the annotation applies to the array element.

If we were to change the proposal to permit annotation of arbitrary
expressions, then the example would indeed be ambiguous.  So at such time
as we permit such annotations, we could re-visit this example.

But even if this example is not a great one, we could still consider the
alternate syntax proposal.  (It would help your case to make an alternate
argument for this syntax.)

>   So, it is probably more consistent if annotation declaration would be 
> outside of the square brackets. Then above example would look like this:
>   Document[] @Readonly [] docs5 = new Document[2] @Readonly [12];


More information about the JSR308 mailing list