简体   繁体   中英

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

I have an annotation with 3 attributes:

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 ?

You do this by providing a default annotaion...

For example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM