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.
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.
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.
For custom types you can do something like this
public @interface SomeAnnotation {
Class<? extends SomeInterface> yourCustomType() default SomeNullInterface.class;
}
/**
* Your custom type
*/
public interface SomeInterface {
}
/**
* Your fake null value type
*/
public interface SomeNullInterface extends SomeInterface {
}
And somewhere in your code you can then check for null like this
if(!yourAnnotation.yourCustomType().isAssignableFrom(SomeNullInterface.class)){
//your value is null
}