I'm working on a project, and my supervisors want me to be able to get the values of enum constants via an annotation processor. For example from the following enum definition:
public enum Animal {
LION(5),
GIRAFFE(7),
ELEPHANT(2),
private int value;
Animal(int value) {
this.value = value;
}
public int Value() {
return value;
}
}
They want me to compile an array of [5, 7, 2].
Note that because I am working within an annotation processor, I am using Element based reflection (not Class based reflection).
My reading of the VariableElement documentation leads me to believe this is impossible.
Note that not all final fields will have constant values. In particular, enum constants are not considered to be compile-time constants.
Does anyone know of a way to get this working?
Thank you for taking the time to read this! --Beka