如何为Annotation TYPE编写可选的默认注释值

时间:2014-12-27 01:29:53

标签: java annotations

根据error-setting-a-default-null-value-for-an-annotations-field

不可能将null影响到可选的默认值,这里是我的情况

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE) 
public @interface SubView {
    Class EntityType();
    String[] Listing();
}

如何编码可选SubView属性的默认值?

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface SubTab {
    String name();
    String[] Fields() default {};
    SubView SubView() default ??? ; //this is optional how to code it?
}

1 个答案:

答案 0 :(得分:3)

反复试验

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface SubTab {
    String name();
    String[] Fields() default {};
    SubView SubView() default @SubView(Listing={}, EntityType=Object.class);
}