[JSR308] Annotations on type parameter bounds

Alex Buckley Alex.Buckley at Sun.COM
Mon Jul 23 09:47:10 EDT 2007


The "Type Parameter Bounds" reference_info structure in the 308 draft 
doesn't seem to properly handle type bounds which are themselves 
parameterized. The example in the draft:

   <T extends @A Object & @B Comparable, U extends @C Cloneable>

can get away with flat values for bound_index, but consider:

   <T extends List<List<@A List<@B String>>>

where if @A has param_index 0, bound_index 0 and @B has param_index 0, 
bound_index 1, then the annotations are indistinguishable (presumably a 
bad thing) from those on:

   <T extends @A List<@B List<List<String>>>

One solution is to drop bound_index and adopt location_length+location 
from "Generic Type Arguments or Arrays":

   <T extends @A List<@B List<List<String>>>
   @A: param_index 0, location_length 1, location 0
   @B: param_index 0, location_length 2, location 0,0

   <T extends List<List<@A List<@B String>>>
   @A: param_index 0, location_length 3, location 0,0,0
   @B: param_index 0, location_length 4, location 0,0,0,0

   <T extends List<List<@A Map<@B Object, @C String>>>> & @D Comparable>
   @A: param_index 0, location_length 3, location 0,0,0
   @B: param_index 0, location_length 4, location 0,0,0,0
   @C: param_index 0, location_length 4, location 0,0,0,1
   @D: param_index 0, location_length 1, location 1

Similarly for "Class extends and implements Clauses": if the superclass 
is List<List<@A List<String>>>, what would type_index be for @A? Do you 
really want it to just be -1?

(BTW, a small spec point: in "Class extends and implements Clauses", 
"When the annotation's target is a type in an extends or implements 
clause" should properly finish with "of a class or interface declaration.")

Alex



More information about the JSR308 mailing list