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