In Java I can do this:
enum Color {RED, BLUE, GREEN };
enum Weight {LIGHT, HEAVY }
Enum e = Color.RED;
assertEquals(Color.RED, e);
e = Weight.HEAVY;
assertEquals(Weight.HEAVY, e);
I can put the enum in a Map and that still works:
Map<String, Enum> map = Maps.newHashMap();
map.put("color", Color.RED);
map.put("weight", Weight.HEAVY);
assertEquals(Color.RED, map.get("color"));
assertEquals(Weight.HEAVY, map.get("weight"));
However, I am not able to do the same with collections of enums.
List<Enum> enumList = new ArrayList<Color>(); //error
Is that not allowed in Java or am I just doing it wrong?
Is there a better way to maintain a mapping of properties to Enums that represent them?