为什么我收到错误“属性值必须是常量”。 null 不是常量吗???
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface SomeInterface {
Class<? extends Foo> bar() default null;// this doesn't compile
}
最佳答案
试试这个
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface SomeInterface {
Class bar() default void.class;
}
它不需要一个新类,并且它已经是 Java 中的一个没有任何意义的关键字。
关于java - 为注释字段设置默认空值时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59849354/