Roman
Roman

Reputation: 66196

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: {} 
}

Upvotes: 20

Views: 18161

Answers (1)

Perception
Perception

Reputation: 80633

Yes, its possible:

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

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

Upvotes: 38

Related Questions