gpt4 book ai didi

java - 为注释字段设置默认空值时出错

转载 作者:行者123 更新时间:2023-12-01 18:45:32 25 4
gpt4 key购买 nike

为什么我收到错误“属性值必须是常量”。 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com