[JSR308] Annotations on type variable declarations

Maurizio Cimadamore Maurizio.Cimadamore at Sun.COM
Wed Feb 25 07:05:14 EST 2009


Hi,
I think that all the discussion can be resumed by Mike's question:

Question:  Is it necessary to add more new enum constants to
java.lang.annotation.ElementType, to distinguish among the locations for
annotations that are exemplified by @Anno1, @Anno2, and @NonNull above?


where the code was:

class Foo<@Anno1 X> {
    @Anno2 X myVariable = ...;
}

In my opinion (and thats why I raised this issue in the first place) 
it's important to distinguish between the two locations; while @Anno2 is 
a plain type-annotation, I think of @Anno1 as a plain 269 annotation, 
which targets a declaration site (while all other kinds of annotations 
defined by 308, except for receiver, are use-site).

In [1] is defined an interesting use of type parameter annotations:

class Foo<@Reified X, Y> {}

where @Reified denotes a type parameter that should be 'reified' at 
runtime (that is, whose type information should be preserved, e.g. by 
exploiting some custom bytecode attributes, so that exact runtime 
type-info can be recovered at runtime).

In such an example, I'd like to be able to specify that @Reified should 
only apply to type variable declarations, and NOT to any other type 
variable use. That's why I think that adding another enum constant 
targeting type-variable declarations (conceptually there are two of 
them, one for method type vars, another for class type vars, but one 
would do the job) it's important.

[1] http://weblogs.java.net/blog/forax/archive/2006/11/reified_generic.html

Maurizio




More information about the JSR308 mailing list