Java - Repeatable Annotation Type


To use an annotation repeatedly in the same context, the annotation type declaration must be annotated with a @Repeatable annotation.


The following code creates EventLog and EventLogs annotation types.

EventLog is annotated with the @Repeatable(EventLogs.class) annotation, which means that it is a repeatable annotation type and its containing annotation type is EventLogs.

@interface EventLog {
        String date();
        String comments();

@interface EventLogs {
    EventLog[] value();

You can use the EventLog annotation to log change history for the Test class.

@EventLog(date="02/01/2018", comments="entry 1")
@EventLog(date="02/21/2018", comments="entry 2")
class Test {