How to create optional parameters for own annotations?

Biju CD picture Biju CD · Aug 19, 2010 · Viewed 78.5k times · Source

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.

Answer

Riduidel picture Riduidel · Aug 19, 2010

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]"; 
}