优点:常量做为Key,在编译期就确定了。Enum做为key,在运行时也可以改变
package enumdemo;import java.util.EnumMap;import java.util.Map;import java.util.Set;public class EnumMaps { public static void main(String[] args) { EnumMapem = new EnumMap (AlarmPoints.class); em.put(AlarmPoints.KITCHEN, new Command() { @Override public void action() { System.out.println("action:kitchen..."); } }); em.put(AlarmPoints.BATHROOM, new Command() { @Override public void action() { System.out.println("action:bathroom"); } }); Set > set = em.entrySet(); for (Map.Entry entry : set) { System.out.println(entry.getKey() + ""); entry.getValue().action(); } System.out.println(em.get(AlarmPoints.UTILITY) + ""); }}enum AlarmPoints { KITCHEN, BATHROOM, UTILITY}interface Command { void action();}