[JSR308] annotations on arrays

Chin Wei Ngan chinwn at comp.nus.edu.sg
Tue Jan 30 19:10:41 EST 2007

> Message: 5
> Date: Tue, 30 Jan 2007 15:57:16 -0500
> From: Eugene Kuleshov <eu at javatx.org>
>  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

Yes, I agree much with what Eugene said that we should
distinguish annotation for the dimensions vs annotation for
the elements. The space within [..] should be for annotating
the index, eg. the example that Michael raised on dependent
type system:


where Length annotation are meant as qualifiers to the indexes.

To talk about the elements, it has to be done outside of
the [..]. In general, we can view

   Document[][] as (((Document)[])[])

If we allow annotations after a type, instead of before,
we may write annotations to the above as:

     (((Document ann1)[] ann2)[] ann3)

where ann1 is for all documents, ann2 is for
the array of documents, while ann3 is for array of array of documents.
I guess post-annotation would correspond to what Eugene suggested,
and if we drop the brackets would look like this:

      Document ann1 [] ann2 [] ann3

I guess brackets are always allowed to mininise ambiguity.
One question may be if we should allow post-annotation
(annotation after a type) in addition to pre-annotation
(annotation before a type).


More information about the JSR308 mailing list