How to create additional parameters for your own annotations?

Below is the annotation code

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

I would like to make datatype optional parameter like

 @ColumnName(value="password") 

must be a valid code.

+65
java annotations
Aug 19 '10 at 9:25
source share
2 answers

It seems that 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]"; } 
+87
Aug 19 '10 at 9:33
source share

To make this optional, you can give it a default value:

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

Then, when using the annotation, you do not need to specify it.

+26
Aug 19 '10 at 9:35 a.m.
source share



All Articles