I have an annotation like this:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
public @interface MyAnnotation {
String name();
Class<InstanceConverter> converter();
What I'm trying to do is make name required and converter optional. It appears that all attributes of an annotation are required by default. How do I make converter optional?
I've read through two articles on annotations and none seem to mention optional attributes.
Thanks.
You should add a default
clause at the right side of the field declaration statement in the annotation @interface definition:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
public @interface MyAnnotation {
String name(); // mandatory
Class<InstanceConverter> converter() default InstanceConverter.class; // optional
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With