[JSR308] array-valued annotations

Ted Neward ted at tedneward.com
Mon Jan 29 21:06:54 EST 2007

I think you're both arguing past each other.

Pavel's correct, in that the array *itself* is an object, managed by the
JVM's memory manager in the same way that any other object is managed. The
thing that the programmer works with is, of course, the reference to the
object, just as it is in every other (non-array) case.

Matt's correct, however, in that Pavel's explanation below implies that a
multidimensional array is *not* a singular object, but an object which in
turn has references to other objects (the other arrays), which in turn have
references to objects, and so on. All of these references must be of the
type specified in the original (root?) type declaration (of Document, in the
examples we've been working with).

I think we're trying to decide if (a) an annotation on a local variable
declaration is part of its type signature, and (b) whether the "type" of an
array dimension in an array-of-arrays declaration can vary from one
dimension to another. Assuming (a) is true, then it would seem that the
language's actions are pretty clear here; for any declaration

T[] t;

then the associated array must contain only T (or type-compatible)
references. The programmer is clearly not allowed to change that--it is
inferred by the compiler. This rule is simply extended for arrays-of-arrays;
a declaration

T[][] t;

is in essence picked apart as

((T)[])[] t;

meaning that the outer rank is an array of T[] references, and the inner
rank is an array of T references. Nowhere are we allowed to change the type
T. If our intent is to follow precedent already established in the language,
then there is no precedent to allow us to vary the type of an array within
its dimensions.

Assuming (a) is false, and that the annotations are not part of the type
signature, then we're in basically the same spot as "final" (that is, the
annotation is effectively another modifier, of the same category as
"final"); does Java allow us to specify "final" on inner dimensions of a
jagged array declaration? My understanding is that it does not, but I've
never tried, so I can't be certain.

Usefulness aside, I don't see how we can support this without requiring a
language change, and that's clearly out of the scope of the charter.

Ted Neward
Java, .NET, XML Services
Consulting, Teaching, Speaking, Writing

> -----Original Message-----
> From: jsr308-bounces at lists.csail.mit.edu [mailto:jsr308-
> bounces at lists.csail.mit.edu] On Behalf Of Matt McCutchen
> Sent: Monday, January 29, 2007 2:09 PM
> To: Pavel Krupets
> Cc: jsr308 at lists.csail.mit.edu
> Subject: Re: [JSR308] array-valued annotations
> On 1/29/07, Pavel Krupets <pavel.krupets at db.com> wrote:
> > Yep. The main point is that array itself is an object (no matter whether
> > it's n-dimensional or array of arrays with different lengths {which I
> > think is a side effect :=)}) and it contains objects with the specified
> > type. So we have two entities to which annotations can be applied.
> I strongly disagree.  According to the Introduction to the Java
> Language Specification, Third Edition, "The language supports arrays
> of arrays, rather than multidimensional arrays."  I take you to mean
> that it should be possible to annotate an array as a whole separately
> from its element type.  I believe that an array whose element type
> happens to be another array should be no exception to this rule: it
> should be possible to annotate all three levels separately.
> Whether it is "appropriate" to use different annotations on different
> levels is the programmer's judgment depending on the problem he/she is
> trying to solve.  But since Michael Ernst has given several examples
> in which annotating different levels of an array separately is useful,
> I think the specification should allow it.
> Matt
> _______________________________________________
> JSR308 mailing list
> JSR308 at lists.csail.mit.edu
> https://lists.csail.mit.edu/mailman/listinfo/jsr308
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.432 / Virus Database: 268.17.14/658 - Release Date: 1/29/2007
> 2:49 PM

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.14/658 - Release Date: 1/29/2007
2:49 PM

More information about the JSR308 mailing list