简体   繁体   English

是否可以为另一个注释类型的注释字段指定默认值?

[英]Is it possible to specify default value for annotation field of another annotation type?

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

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

And one more case : 还有一个案例

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

Yes, its possible: 是的,可能的:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java:如何将默认值设置为注释,并将另一个注释作为其属性? - Java: how to set default value to annotation with another annotation as its attribute? Java批注:将字段值用于另一个字段 - Java annotation: using a field value into another field 使用默认值在另一个自定义注释中定义自定义注释 - Define custom annotation within another custom annotation with default value 如何为Annotation TYPE编写可选的默认注释值 - How to code optional default annotation value for Annotation TYPE 在“注释”中为注释类型attibute提供类似于“ NO_VALUE”的默认值 - Provide similar to 'NO_VALUE' default for Annotation type attibute in the Annotation 在Lombok中使用@Builder或@Getter注释的默认字段值 - Default field value with @Builder or @Getter annotation in Lombok 是否可以从注释中的字段值调用方法? - Is it possible to call a method from a field value in an annotation? 如何在 Spring @Value 注释中正确指定默认值? - How to correctly specify a default value in the Spring @Value annotation? Java Spring验证-为自定义验证注释指定字段类型 - java spring validation - specify field type for custom validation annotation 如何在Java中指定应将注释应用于的字段类型? - How can I specify the type of the field that an Annotation should be applied to in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM