Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 509
Dragon Avatar asked Mar 31 '14 11:03

Dragon


1 Answers

You do this by providing a default annotaion...

For example:

public @interface Author {
    String name();
    Date date() default @Date(year=2014);
}
like image 112
Balder Avatar answered Oct 13 '22 12:10

Balder