I have written my custom annotation and is working fine if i use it as below.
@MyAnnotation("sun")
public void getResult(String id){
}
MyAnnotation.java
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
String value();
}
above code is working fine. Now instead of hard coding "sun", i would like to keep it in an Enum as below.
public enum WeekDay{
SUNDAY("sun"), MONDAY("mon");
private String day;
WeekDay(String day) {
this.day= day;
}
public String getDay() {
return this.day;
}
}
and now with in annotation i do as below.
@MyAnnotation(WeekDay.SUNDAY.getDay())
public void getResult(String id){
}
above code gives compilation error in eclipse. It says The value for annotation attribute MyAnnotation.value must be a constant expression. Am i doing anything wrong here?
Thanks!