[JSR308] array-valued annotations

Michael Ernst mernst at csail.mit.edu
Thu Jan 25 15:51:25 EST 2007


Pavel-

Thanks for your suggestions.

> I don't think it's appropriate to use annotations like:
> "Document[][@Readonly]". What I mean is that there is no much sense in
> specifying different annotations for different dimensions of the array. If
> such behavior is needed other types can be used (like List<...>, etc). I
> think annotations should be used only with:
> 
> - array as an object (like: @NonNull @Readonly Document[][] doc = ...)
> - objects which are stored inside arrays (like: Document @NonNull
> @Readonly [][] doc = ...)
> 
> The reason behind this is that array (one or multi-dimensional) is an
> 'atomic' type which has type of stored object and dimensions. Just want to
> keep things simple.

Arrays are not atomic types in Java.  For example, is is possible for any
level of a multi-dimensional array to be null, for different rows of an
array to have different lengths, and for rows to be reassigned; array
cloning is shallow; etc.

I interpret your argument as follows:

  It should be possible to express certain properties about data structures
  when those data structures are expressed using Lists, but not when those
  data structures are expressed using arrays.

(I've made the argument as simply as possible, but I am not trying to
caricature your argument.  Please clarify if I have misunderstood.)

I would prefer to have a uniform and expressive system rather than one that
makes arbitrary restrictions.  And, I prefer to accommodate existing code
rather than forcing programmers to rewrite their data structures.  All of
this is particularly true because there are concrete examples where there
is value in annotating specific levels of an array.  Here are a few
examples.

 1. The current proposal (at
    http://pag.csail.mit.edu/jsr308/java-annotation-design.pdf) gives this
    example:
      Titanium [Yelick 1998] requires the ability to place the \code{local}
      annotation (indicating that a memory reference in a parallel system
      refers to data on the same processor) on various levels of an array,
      not just at the top level.
 2. In a dependent type system, where one wishes to specify the dimensions
    of an array type:  Object[@Length(3)][@Length(10)] for a 3x10 array.
 3. An immutability type system needs to be able to specify which levels of
    an array may be modified.  Consider a two-dimensional array where we
    wish to permit leaf-level elements to be replaced, but the overall
    shape of the array (its dimensions) may not be changed.  The top-level
    array is immutable, but the inner
    arrays are mutable, but the 

It is possible that despite the benefits of permitting any level of an
array to be specified, that we would nonetheless choose to restrict that
expressiveness.  (For example, it could simplify the syntax or be less
confusing.)  Let's keep discussing this; I'm not convinced that we yet have
evidence regarding which choice is better.

                    -Michael Ernst
                     mernst at csail.mit.edu



More information about the JSR308 mailing list