Search code examples
javaannotations

How to create optional parameters for own annotations?


Following is the annotation code

public @interface ColumnName {
   String value();
   String datatype();
 }

I would like to make datatype an optional parameter, for example

@ColumnName(value="password") 

should be a valid code.


Solution

  • Seems like the first example in the official documentation says it all ...

    /**
     * Describes the Request-For-Enhancement(RFE) that led
     * to the presence of the annotated API element.
     */
    public @interface RequestForEnhancement {
        int    id();
        String synopsis();
        String engineer() default "[unassigned]"; 
        String date()     default "[unimplemented]"; 
    }