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.
Use Varargs to Have Optional Parameters in Java In Java, Varargs (variable-length arguments) allows the method to accept zero or multiple arguments. The use of this particular approach is not recommended as it creates maintenance problems.
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]"; }
To make it optional you can assign it a default value like that:
public @interface ColumnName { String value(); String datatype() default "String"; }
Then it doesn't need to be specified when using the Annotation.
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