I am thinking this may not be possible in Java because annotation and its parameters are resolved at compile time. I have an interface as follows,
public interface FieldValues {
String[] FIELD1 = new String[]{"value1", "value2"};
}
and another class as,
@SomeAnnotation(locations = {"value1", "value2"})
public class MyClass {
....
}
I mark many classes with the annotation and I would like to know if I can avoid specifying the strings in every annotation I would instead prefer to use
@SomeAnnotation(locations = FieldValues.FIELD1)
public class MyClass {
....
}
However this gives compilation errors like annotation value should be an array initializer etc. Does someone know how I can use a String constant or String[] constant to supply value to an annotation?