[JSR308] annotations on arrays

Eugene Kuleshov eu at javatx.org
Tue Jan 30 15:57:16 EST 2007

  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];



More information about the JSR308 mailing list