[type-annos-observers] ordering of annotated array brackets
Alex Buckley
alex.buckley at oracle.com
Tue Mar 4 13:47:10 PST 2014
On 3/4/2014 9:29 AM, Michael Ernst wrote:
> There was some text in the old specification about this issue. It was
> commented out in September 2011 for brevity, but not because of
> controversy.
>
> In this (deprecated but legal) syntax, in each component you read
> left-to-right, like this:
>
> @English String @NonNull [] [] [] arr1, arr2 @Length(10) [] [] [];
> 3-------------> 2---------------> 1------------------>
>
> As another example, consider
>
> @A T @B [] arr1, arr2 @C [];
>
> arr1 should have the same annotations as the elements of arr2. So,
>
> @A T @B [] arr2 @C [];
>
> should be equivalent to
>
> @A T @C [] @B [] arr2;
I don't understand this at all. Allow me to refer to section 2.2.1 of
java-annotation-design.pdf:
--
An important property of this syntax is that, in two declarations that
differ only in the number of array levels, the annotations mean the same
thing. For example, var1 has the same annotations as the elements of arr2:
@NonNull String var1;
@NonNull String[] arr2;
because in each case @NonNull refers to the String, not the array. This
consistency is especially important since the two variables may appear
in a single declaration:
@NonNull String var1, arr2[];
--
So in a field declaration with two declarators, arr1 and arr2:
@A T @B [] arr1, arr2 @C [];
the extra dimension in the second declarator should not affect the type
or annotations of the first declarator. Yet you seem to be saying that
arr2's extra dimension affects the type of arr1?!
Alex
More information about the type-annotations-spec-experts
mailing list