I\'m unable to use an Enum taken from a Constant as a parameter in an annotation. I get this compilation error: \"The value for annotation attribute [attribute] must be an e
My solution was
public enum MyEnum {
FOO,
BAR;
// element value must be a constant expression
// so we needs this hack in order to use enums as
// annotation values
public static final String _FOO = FOO.name();
public static final String _BAR = BAR.name();
}
I thought this was the cleanest way. This meets couple of requirements:
@Annotation(foo = MyEnum._FOO)EDIT
This leads occasionally to compilation error, which leads to the reason of the original element value must be a constant expression
So this is apparently not an option!