[JSR308] Others possible syntaxes for type annotations

Eugene Kuleshov eu at javatx.org
Mon May 21 02:33:06 EDT 2007

Igor Peshansky wrote:
> I always understood that the type parameters of a generic type are part
> of the type (i.e., List<Integer> is a different type from List<String>,
> rather than them both being constrained Lists).  So it seems that whatever
> annotations you want to put on the type should follow the type parameters,
> otherwise they look like they're only constraining the base type (in my
> example, List).
  Igor, first of all, this syntax is not even being considered by the 
JSR EG just yet. Mainly because there wasn't solid argument why it would 
work better then syntax currently implemented in the prototype, or 
syntax that Neal Gafter recently recently proposed.

  I do agree that annotations done in this way can be confusing to 
someone who see them for the first time without reading the specs. In 
this regard the less confusing syntax is the one implemented in the 
current prototype (and at the same time that syntax has some arguable 

> Also, Maxim is right -- the annotations that precede type parameters with
> no separator do look like they are annotating the parameters, not the base
> type.
  The reason I suggested to not use any separators for this syntax is 
because it doesn't introduce any ambiguity and because annotations in 
other places of the Java grammar don't have any separators. Let me give 
you an example that shows that adding separator can be actually more 

  Map<Integer, String, @NotNull> var = new HashMap<Integer, String>();

  Now on a type declaration we have 3 parameters and right part only 
have two. I think it is wrong and actually demonstrating that type 
annotations are part of the concrete type, but aren't really generic 
parameters. So, one of the following declarations is actually less 

  Map<@NotNull Integer, String> var = new HashMap<Integer, String>();
  Map<Integer, String @NotNull> var = new HashMap<Integer, String>();
  Using ";" instead of "," would probably mean that annotation separator 
is mandatory and you'll end up with completely unnecessary 
clarifications like this:

  Foo<;@NotNull> foo;


More information about the JSR308 mailing list