Error setting a default null value for an annotation's field

前端 未结 7 1957
渐次进展
渐次进展 2020-11-30 08:20

Why am I getting an error \"Attribute value must be constant\". Isn\'t null constant???

@Target(ElementType.TYPE)
@Retention(RetentionPolicy         


        
相关标签:
7条回答
  • 2020-11-30 09:08

    It seem there is one other way of doing it.

    I don't like this either, but it might work.

    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface SomeInterface {
        Class<? extends Foo>[] bar() default {};
    }
    

    So basically you create an empty Array instead. This seems to allow a default value.

    0 讨论(0)
提交回复
热议问题