【发布时间】:2020-01-22 20:58:04
【问题描述】:
我正在创建一个自定义注释
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyFramework {
public Integer index() default null; // Compiler complains here
}
编译器抱怨null 是不允许的。我不想让索引字段原始类型int,因为它没有意义。有没有办法为注释字段设置默认的null 值?
Error setting a default null value for an annotation's field 的答案提到了Class 类型,因此解决方案有效,但不适用于Integer、Double 等。
【问题讨论】:
标签: java annotations