Interaction between @Target meta-annotations and fully-qualified types

Michael Ernst mernst at cs.washington.edu
Mon Apr 22 13:50:49 PDT 2013


Alex-

> I note that a method whose result is 'void' (and hence has no return type)
> cannot allow a solely-TYPE_USE annotation where a METHOD annotation
> previously stood.

Right.  This example already appeared in the specification, so it's not a 
change nor even a clarification.  As we have previously discussed, you would 
never expect to change (say) a METHOD annotation to a FIELD annotation and 
write it in the same places, so we wouldn't expect to make other @Target 
changes either.

> This is an argument against partitioning type annotations
> and declaration annotations.

I don't see this argument.  The spec notes that it is bad style to have a 
single annotation that is both a type annotation and a declaration annotation.

The only use that I can think of for such an annotation is if a programmer 
wishes to use two different tools, one of which operates on type annotations 
and the other of which operates on declaration annotations, and both of which 
expect the annotation to have exactly the same name.  The spec notes that that 
is an unusual and temporary situation.  The existence of this situation should 
not change style advice, much less change the way that annotations are 
conceptualized.  (But, is this situation even what you are talking about?  I 
am not sure about that.)

> The code below shows it is necessary to add
> TYPE_USE to METHOD in the annotation type's declaration, assuming the
> annotation type is to be applied widely.
>
>   @MAnno void myMethod1() { ... }   // legal, one method annotation
>   @TAnno void myMethod2() { ... }   // illegal
>   @MTAnno void myMethod3() { ... }  // legal, one method annotation

It isn't desirable (except in one specific and temporary situation) for an 
annotation type to be used both in type and declaration positions.  Maybe that 
fact eliminates confusion and makes this discussion unnecessary.

                     -Mike


More information about the type-annotations-spec-experts mailing list