TYPE_USE annotations on type parameter declarations
Michael Ernst
mernst at cs.washington.edu
Wed Dec 9 01:09:16 UTC 2015
I have a question about use of TYPE_USE annotations on type parameter
declarations.
I did not expect this code to compile:
@Target(ElementType.TYPE_USE)
@interface TU { }
// This is surprising:
public class TypeUseAtParameter<@TU T> {
}
because I thought that a @Target(TYPE_USE) annotation could not be written
on the declaration of a type parameter. In fact, javac (from JDK 8 or JDK
9) accepts it. See the attachment for a full, compilable test case.
Section 9.6.4.1 says, "There are 16 type contexts (§4.11), all represented
by the enum constant TYPE_USE of java.lang.annotation.ElementType.", and
section 4.11 does not include a type parameter declaration as one of these
locations.
Am I confused, or may there be a problem with javac?
Thanks!
-Mike
-------------- next part --------------
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target(ElementType.TYPE_USE)
@interface TU { }
@Target(ElementType.TYPE_PARAMETER)
@interface TP { }
// This is surprising:
public class TypeUseAtParameter<@TU T> {
}
// This is expected:
class TypeParameterAtParameter<@TP T> {
}
More information about the compiler-dev
mailing list