[type-annos-observers] ordering of annotated array brackets
Alex Buckley
alex.buckley at oracle.com
Tue Mar 4 15:13:37 PST 2014
On 3/3/2014 1:55 PM, Michael Ernst wrote:
>> 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?!
>
> I didn't intend to say that.
>
> Can you explain how you think I'm saying that arr2's extra dimension
> affects the type of arr1?
// Using the JLS ch.10 terminology carefully re: array elements v. array
components.
Consider:
>>> 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 think you're saying: 1) the elements of arr1 are @B, and 2) the
elements of arr2 should be the same as the elements of arr1. I agree
with (1) but not (2). I guess (2) is deduced from the principle that:
"in two declarations that differ only in the number of array levels, the
annotations mean the same thing."
That is, arr1 and arr2 differ only in the number of array levels, so if
@B applies to arr1's element type, then @B should apply to arr2's
element type, right?
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 [];
The principle of least surprise is important.
Alex
> -Mike
>
>> Subject: Re: [type-annos-observers] ordering of annotated array brackets
>> From: Alex Buckley <alex.buckley at oracle.com>
>> To: type-annotations-spec-experts
>> <type-annotations-spec-experts at openjdk.java.net>
>> Date: Tue, 04 Mar 2014 13:47:10 -0800
>>
>> 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