[type-annos-observers] ordering of annotated array brackets
Markus Keller
markus_keller at ch.ibm.com
Wed Mar 5 02:26:44 PST 2014
Alex Buckley <alex.buckley at oracle.com> wrote on 2014-03-05 00:13:37:
> I disagree where post-identifier brackets are concerned, because I think
> that adding them should not cause the reader to do gymnastics on the
> annotated array type. It's simply astonishing that post-identifier []
> pairs are inserted _before_ the normal [] pairs. I keep recalling the
> beauty of:
>
> @A T x;
> @A T[] y;
>
> whereby adding [] doesn't affect anything to the left of []; in that
> vein, adding @C [] should not affect anything to the left @B [].
>
> @A T @B [] arr1;
> @A T @B [] arr2 @C [];
Note that this is not just about post-identifier [] pairs. It's a direct
consequence of the notation for multi-dimensional array types.
If you have a declaration
@A T @B [] @C [] arr3;
then arr3 is of type "@B-array of @C-array of @A T", and the component
type of arr3 is
@A T @C [] arr3component = arr3[7];
because "@B []" is the outermost dimension. This is a bit surprising, but
as argued in [1], the surprise is that array brackets have to be written
after the element type, and not before. Using a generic List "@B-List of
@C-List of @A T", a similar type would look like this:
@B List<@C List<@A T>> arrList3;
See how the order of annotations is @B, @C as well when @B is the
outermost type annotation?
[1]
http://types.cs.washington.edu/jsr308/specification/java-annotation-design.html#array-syntax
Markus
More information about the type-annotations-spec-observers
mailing list