定义Java接口时,可以使用类型参数声明方法,例如:
public interface ExampleInterface {
<E extends Enum<E>> Class<E> options();
}
Run Code Online (Sandbox Code Playgroud)
同样的事情在注释中不起作用.例如,这是非法的:
public @interface ExampleAnnotation {
<E extends Enum<E>> Class<E> options();
}
Run Code Online (Sandbox Code Playgroud)
我可以通过使用原始类型得到我想要的东西Enum:
public @interface ExampleAnnotation {
@SuppressWarnings("rawtypes")
Class<? extends Enum> options();
}
Run Code Online (Sandbox Code Playgroud)
究竟是什么原因导致无法使用类型参数声明注释属性?