[type-annos-observers] ordering of annotated array brackets

Markus Keller markus_keller at ch.ibm.com
Thu Mar 6 16:57:24 UTC 2014


Alex Buckley <alex.buckley at oracle.com> wrote on 2014-03-05 20:34:20:
> Post-identifier brackets are a corner case, and mixed array syntax is a 
> corner case of that corner case. It's unreasonable to bend a core part 
> of the language - i.e. the rules for "declared type of a field / local 
> var / formal parameter" - to support a corner case of a corner case.

I'm sure we can find a better wording for the paragraph in 10.2, so that 
we don't have to sacrifice the internal consistency of the array type 
notations. And the new wording can even add the missing definition of the 
array brackets order for non-mixed array types. Type annotations are part 
of the language now, so they need to be specified. The rules for the core 
part of the language don't have to be changed much.

Proposal:

* Add to 10.1:
-----
The leftmost bracket pair of an array type stands for the outermost array 
dimension; a following bracket pair for the array's component type, and so 
on. Each bracket pair can be annotated with type annotations (§9.7.4).

        <informal>
        For example, given the field declaration:
 
                @C int @A [] @B [] f;
 
        @A applies to the array type int[][], @B applies to its component 
type int[], and @C applies to the element type int.
        </informal>
-----

* Change 10.2:
-----
[..] the array type of a variable is denoted by the array type that 
appears at the beginning of the declaration, extended by any bracket pairs 
that follow the variable's Identifier in the declarator.

If present, the first bracket pair that follows the variable's identifier 
stands for the outermost array dimension; a following bracket pair for the 
array's component type, and so on. The component type of the last array 
dimension is the type that appears at the beginning of the declaration 
(and that type can be an array type itself).
-----

The last example in 10.2 could get a clarifying type annotation:

        float[][] f[][], g[][][], h @A []; // Yechh!
...
        float @A [][][] h;


Markus



More information about the type-annotations-spec-observers mailing list