java 并发编程实战书籍学习 第四章 unmodifiableMap
来源:互联网 发布:上海游奇网络老板是谁 编辑:程序博客网 时间:2024/06/15 02:02
public class CollectionSycnchroize {
public static void main(String[] args) {
HashMap<String, Point> locationsMap = new HashMap<String, Point>();//创建一个map
Point point = new Point(1, 1);
locationsMap.put("1", point);//放入一个 对象
Map<String, Point> unmodifiableMap = Collections.unmodifiableMap(locationsMap);//创建一个不可修改map
Point pointGeted = unmodifiableMap.get("1");//获取map中的对象
pointGeted.setX(2);
System.out.println(unmodifiableMap.get("1"));//运行正常
unmodifiableMap.put("1", new Point(2, 2));//报错
}
public static class Point{
private int x;
private int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public Point(int x, int y) {
super();
this.x = x;
this.y = y;
}
public Point() {
super();
}
@Override
public String toString() {
return "Point [x=" + x + ", y=" + y + "]";
}
}
}
public static void main(String[] args) {
HashMap<String, Point> locationsMap = new HashMap<String, Point>();//创建一个map
Point point = new Point(1, 1);
locationsMap.put("1", point);//放入一个 对象
Map<String, Point> unmodifiableMap = Collections.unmodifiableMap(locationsMap);//创建一个不可修改map
Point pointGeted = unmodifiableMap.get("1");//获取map中的对象
pointGeted.setX(2);
System.out.println(unmodifiableMap.get("1"));//运行正常
unmodifiableMap.put("1", new Point(2, 2));//报错
}
public static class Point{
private int x;
private int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public Point(int x, int y) {
super();
this.x = x;
this.y = y;
}
public Point() {
super();
}
@Override
public String toString() {
return "Point [x=" + x + ", y=" + y + "]";
}
}
}
阅读全文
0 0
- java 并发编程实战书籍学习 第四章 unmodifiableMap
- java 并发编程实战书籍学习 第五章,CountDownLatch,FutureTask,CyclicBarrier,Semaphore学习
- Java并发编程实战(学习笔记三 第四章 对象的组合)
- 《Java并发编程实战》第四章 对象的组合 读书笔记
- Java并发编程实战第四章对象的组合
- java 并发编程实战 第四天
- Java并发编程实战第三章学习
- 《JAVA并发编程实践》学习笔记(第四.五章)
- java并发编程实战阅读笔记(第四章)对象的组合
- Java 并发编程实战学习笔记
- 学习java并发编程实战(一)
- java并发编程第四章 总结
- Java并发编程实战
- Java并发编程实战--
- Java并发编程实战-
- Java 并发编程实战
- java并发编程实战
- Java并发编程实战
- telnet测试端口
- 用powerDesigner生成数据库时_用列名称代替注释
- Java基础:浅析Java中的final关键字
- C语言之指针初涉
- hbase的coprocessor使用
- java 并发编程实战书籍学习 第四章 unmodifiableMap
- socket推送
- (windows)python安装opencv
- 随笔——新思路
- FPGA作为从机与STM32进行SPI协议通信---Verilog实现 [转]
- 快速下载vs2013等开发工具--资源查找
- 内连接、左外连接、右外连接、交叉连接区别
- java.sql.SQLException: The table 'label_result' is full
- 【我的Java笔记】Collection集合的概述 & List