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

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

  •  23-04-2021
  •  | 
  •  

Pregunta

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

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

And one more case:

public @interface AnotherOuterAnnotation {
    InnerAnnotation[] value() default ??? UPD: {} 
}
¿Fue útil?

Solución

Yes, its possible:

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

public @interface OuterAnnotation {
    InnerAnnotation value() default @InnerAnnotation(value = "Goodbye");
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top