Is it possible to specify default value for annotation field of another annotation type?

StackOverflow https://stackoverflow.com/questions/9153177

  •  23-04-2021
  •  | 
  •  

Вопрос

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

public @interface OuterAnnotation {
    InnerAnnotation value() default ???
}

And one more case:

public @interface AnotherOuterAnnotation {
    InnerAnnotation[] value() default ??? UPD: {} 
}
Это было полезно?

Решение

Yes, its possible:

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

public @interface OuterAnnotation {
    InnerAnnotation value() default @InnerAnnotation(value = "Goodbye");
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top