You can not. I believe you have FOUR choices here. All four attempt a resolution but with a slightly modified method...
Method One: Try the built-in name() on an enum. This is fine if you don't require any special identifying format.
String name = Modes.mode1.name(); // Returns
the name of this enum constant, specifically as stated in its enum statement.
Method Two: add overriding features to your enums if you require more direction
public enum Modes {
mode1 ("Fancy Mode 1"),
mode2 ("Fancy Mode 2"),
mode3 ("Fancy Mode 3");
private final String name;
private Modes(String s) {
name = s;
}
public boolean equalsName(String otherName) {
// (otherName == null)
check is not required because name.equals(null) returns false
return name.equals(otherName);
}
public String toString() {
return this.name;
}
}
- Method Three: Try static finals rather of enums:
public final class Modes {
public static final String MODE_1 = "Fancy Mode 1";
public static final String MODE_2 = "Fancy Mode 2";
public static final String MODE_3 = "Fancy Mode 3";
private Modes() { }
}
- Method Four: interfaces hold each field public, static and final:
public interface Modes {
String MODE_1 = "Fancy Mode 1";
String MODE_2 = "Fancy Mode 2";
String MODE_3 = "Fancy Mode 3";
}