[JSR308] annotations on arrays

Eugene Kuleshov eu at javatx.org
Tue Jan 30 18:25:17 EST 2007

Perry James wrote:
>    You're right that parsing raises an issue, since the grammar 
> defines an annotation as
> /Annotation:
>         /|@|/ TypeName [|
> (| [Identifier |=|] ElementValue|)|]/
  Perry, it doesn't seem like it is related. It is not possible to have 
annotation like @ReadOnly[], so syntax I am suggesting won't be 
conflicting and can't be interpreted in a more then one way.
  More over I think it is more consistent with the other annotation 
place holders where annotation is always prepends the annotated object 
and in case of arrays it is for some reason is inside.
>    One possibility would be to use a comma (or [semi]colon or some 
> other punctuation) between the annotation and an assignment expression 
> and not requiring punctuation when there's no assignment.
>    Keeping all of the description of a dimension within the brackets 
> and having no extra punctuation in a very common case seems desirable.
>    Is this workable?  How do you find the notation?
  I am not sure if adding additional punctuation is a good idea. It 
should be sufficient to have just annotation and syntax I've suggested 
does address that. So, if you take annotations out of the following code 
it would still compile.

  Document[] @Readonly [] docs5 = new Document[2] @Readonly [12];

  I think it is also related to the Tennent's Correspondence Principle. 
See some explanation at Neal Gafter blog at 


> On 1/30/07, *Eugene Kuleshov* <eu at javatx.org <mailto:eu at javatx.org>> 
> wrote:
>       Apparently annotations on arrays is quite hot topic and even I very
>     much would like to avoid it, there is one thing worth to mention.
>       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.
>       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];
>       Thoughts?
>       regards,
>       Eugene

More information about the JSR308 mailing list