简体   繁体   English

Java:如何将默认值设置为注释,并将另一个注释作为其属性?

[英]Java: how to set default value to annotation with another annotation as its attribute?

I have an annotation with 3 attributes: 我有一个带有3个属性的注释:

public @interface Date {
    int day() default 1;
    int month() default 1;
    int year() default 2000;
}

And annotation that uses previous annotation as attribute: 以及使用先前注释作为属性的注释:

public @interface Author {
    String name();
    Date date(); //default value here
}

How to set default value for attribute date ? 如何设置属性date默认值?

You do this by providing a default annotaion... 您可以通过提供默认注释来完成此操作...

For example: 例如:

public @interface Author {
    String name();
    Date date() default @Date(year=2014);
}

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

相关问题 Java批注:将批注属性的值传递给另一个批注 - Java annotations: pass value of annotation attribute to another annotation 如何在 java 中用另一个注解来注解一个注解? - How to annotate an annotation with another annotation in java? Java注解:元素声明为方法,但值设置为属性 - Java annotation: elements declared as method but value set as attribute 使用默认值在另一个自定义注释中定义自定义注释 - Define custom annotation within another custom annotation with default value 是否可以为另一个注释类型的注释字段指定默认值? - Is it possible to specify default value for annotation field of another annotation type? 如何通过注释注入对象并在此对象上设置属性值 - How to inject an object via annotation and set an attribute value on this object 如何使用属性中的Spring @Value来设置注释属性 - How to use a Spring @Value from properties to set an annotation attribute 如何根据 Spring Boot 中的活动配置文件设置注释属性值? - How to set annotation attribute value based on the active profile in Spring Boot? 如何将默认值设置为注释变量作为注释变量的类类型? - How to set default value to annotation variable as the class type of the variable annotated? 创建对象时如何处理注释和设置默认值 - How to process annotation and set a default value while creating object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM