I want to use an Annotation in compile-safe form.
To pass the value() to the Annotation i want to use the String representation of an enum.
Is there a way to use @A with a value from enum E ?
public class T {
public enum E {
a,b;
}
// C1: i want this, but it won't compile
@A(E.a)
void bar() {
// C2: no chance, it won't compile
@A(E.a.toString())
void bar2() {
}
// C3: this is ok
@A("a"+"b")
void bar3() {
}
// C4: is constant like C3, is'nt it ?
@A(""+E.a)
void bar4() {
}
}
@interface A {
String value();
}
Update
I need the String type in @A.
The point is i can do this
@A("" + 1)
void foo() {
}
But here the compiler claims "attribute value must be constant". Is'nt E.a constant ?
@A("" + E.a)
void foo() {
}