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
defaultclause at the right side of the field declaration statement in the annotation @interface definition: