Suppose开发者_运维百科 that you have:
Map<something of enum type, Object>;
If you know the enum, how do you gain access to the ObjecT?
For enums it works the same way as for maps in general:
Object value = map.get(enumKey);
Note that with enum keys, it is recommended to use an EnumMap
instead of HashMap
.
Use get
:
Object result = map.get(key);
http://download.oracle.com/javase/tutorial/java/javaOO/enum.html
Enums are objects in java. As such, they can be used as keys in the get method.
精彩评论