【问题标题】:Is it possible to specify default value for annotation field of another annotation type?是否可以为另一种注释类型的注释字段指定默认值?
【发布时间】:2012-02-05 21:27:32
【问题描述】:
public @interface InnerAnnotation {
    String value() default "hello";
}

public @interface OuterAnnotation {
    InnerAnnotation value() default ???
}

还有一个案例

public @interface AnotherOuterAnnotation {
    InnerAnnotation[] value() default ??? UPD: {} 
}

【问题讨论】:

    标签: java annotations jls


    【解决方案1】:

    是的,有可能:

    public @interface InnerAnnotation {
        String value() default "hello";
    }
    
    public @interface OuterAnnotation {
        InnerAnnotation value() default @InnerAnnotation(value = "Goodbye");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-01
      • 2021-06-01
      • 1970-01-01
      • 2021-02-08
      • 2010-11-13
      • 2018-05-26
      相关资源
      最近更新 更多