优点:常量做为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) {
EnumMap<AlarmPoints, Command> em = new EnumMap<AlarmPoints, Command>(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<Map.Entry<AlarmPoints, Command>> set = em.entrySet();
for (Map.Entry<AlarmPoints, Command> 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();
}

最新文章

  1. 【Alpha】Daily Scrum Meeting第三次
  2. ASP.NET MVC使用Bootstrap系列(5)——创建ASP.NET MVC Bootstrap Helpers
  3. shell与kernel的理解 转载
  4. Linux下如何查看哪些端口处于监听状态
  5. C/C++中define的使用
  6. subllime text 创建可复用的代码片段
  7. [转]Android图片下载
  8. HBase 手动 flush 机制梳理
  9. Java 反射的理解
  10. MySQL的入门
  11. python3 Serial 串口助手的接收读取数据
  12. 面试HashMap之追命5连问
  13. (转)从一道面试题彻底搞懂hashCode与equals的作用与区别及应当注意的细节
  14. ubuntu 用 apt get 安装某个包的某个版本
  15. Aysnc的异步执行的线程池
  16. idea 设置 转自 https://www.cnblogs.com/jajian/p/8136672.html
  17. zookeeper基础知识
  18. NAS DAS SAN 磁带机 tco
  19. MPI 派生数据类型 MPI_Type_create_struct(),MPI_Type_contiguous(),MPI_Type_vector(),MPI_Type_create_hvector(),MPI_Type_indexed()
  20. Delphi IDHTTP用法详解

热门文章

  1. 线程锁的概念函数EnterCriticalSection和LeaveCriticalSection的使用方法
  2. Oracle数据库的锁类型
  3. WITH AS
  4. Ubuntu常用软件推荐,图文详细说明及下载
  5. JS判断用户连续输入
  6. SQL server 表数据改变触发发送邮件
  7. 【原创】POJ 1703 &amp;&amp; RQNOJ 能量项链解题报告
  8. hive的非交互模式
  9. A左右ndroid正在使用Uri监视数据库中的更改
  10. unity简易小地图的实现(NGUI)