Is there a standard way to get an enum instance based on a non-enum value?
For example, with good old static constants you can have
public class Color {
public static final int RED = 0;
public static final int GREEN = 1;
public static final int BLUE = 2;
}
Then later you get some values from a database, pass them around functions, and you can always do a check for "if (c == Color.RED)" and so forth.
If Color was a
java enum, would it be possible to get an instance of RED from the int 0 without having to have an explicit mapping (i.e. Map<Integer,Color> idToColor), or even worse looping through all the enum values looking for the one with the specific property?
Thanks in advance,
Yuriy