[JSR308] array-valued annotations

Michael Ernst mernst at csail.mit.edu
Sun Jan 28 09:58:57 EST 2007


> a multidimensional array has to contain all the same type,
> regardless of the number of dimensions.

I agree that the type at the "leaves" must all be the same -- and they
must all have the same annotation.

However, Java does support different types at different levels of an
array.  For instance, consider an array of type Document[][].

 * The first level of the array has type Document[][].
 * The next level (i.the first level's elements) has type Document[].
 * The final level (the leaves) has type Document.

These are distinct types, though Java enforces that they have a
specific relationship to one another.

It seems useful to permit different annotations on the distinct types
at each level.  However, the types/annotations at different levels
should have specific relationships to one another, just as array types
already do.  The syntax can enforce this, just as that for array types
already does.  For instance, you correctly note that the type
"Document[Object[]]" makes no sense; and the Java syntax makes it
impossible to write such a nonsensical type.

                    -Michael Ernst
                     mernst at csail.mit.edu

More information about the JSR308 mailing list