Given the following java enum:
public enum AgeRange {
A18TO23 {
public String toString() {
return \"18 - 23\";
}
},
The class overrides "toString()" - so, to get the reverse operation, you need to override valueOf()
to translate the output of toString()
back to the Enum values.
public enum AgeRange {
A18TO23 {
public String toString() {
return "18 - 23";
}
public AgeRange valueOf (Class enumClass, String name) {
return A18T023
}
},
.
.
.
}
Buyer beware - uncompiled and untested...
The mechanism for toString()
and valueOf()
is a documented part of the API