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

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

  •  23-04-2021
  •  | 
  •  

Domanda

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

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

And one more case:

public @interface AnotherOuterAnnotation {
    InnerAnnotation[] value() default ??? UPD: {} 
}
È stato utile?

Soluzione

Yes, its possible:

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

public @interface OuterAnnotation {
    InnerAnnotation value() default @InnerAnnotation(value = "Goodbye");
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top