相关疑难解决方法(0)

带有类型参数的注释属性

定义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)

究竟是什么原因导致无法使用类型参数声明注释属性?

java generics annotations

26
推荐指数
5
解决办法
3万
查看次数

标签 统计

annotations ×1

generics ×1

java ×1