当前位置:网站首页>guava:Collections.unmodifiableXXX创建的collection并不immutable
guava:Collections.unmodifiableXXX创建的collection并不immutable
2022-07-06 13:10:00 【amadeus_liu2】
一、示例
package com.example.app;
import com.google.common.collect.ImmutableSet;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class ImmutableTest {
public static void main(String[] args) {
List<String> stringList=new LinkedList<>();
stringList.add("abc");
stringList.add("def");
List<String> stringList1 = Collections.unmodifiableList(stringList);
stringList.remove(0);
System.out.println(stringList1);
}
}
运行程序输出:
不能通过Collections.unmodifiableXXX创建的引用修改对象,但因原始的stringList是可以修改的,而stringList1和stringList指向同一个对象,stringList修改必然会使stringList1发生变化。
边栏推荐
- Interviewer: what is the internal implementation of ordered collection in redis?
- 14年本科毕业,转行软件测试,薪资13.5K
- 面试官:Redis中有序集合的内部实现方式是什么?
- @PathVariable
- Quick news: the flybook players' conference is held online; Wechat payment launched "education and training service toolbox"
- 20220211 failure - maximum amount of data supported by mongodb
- Nodejs教程之Expressjs一篇文章快速入门
- Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
- Is it profitable to host an Olympic Games?
- 爱可可AI前沿推介(7.6)
猜你喜欢

3D face reconstruction: from basic knowledge to recognition / reconstruction methods!

【Redis设计与实现】第一部分 :Redis数据结构和对象 总结

HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅

PHP saves session data to MySQL database

缓存更新策略概览(Caching Strategies Overview)

3D人脸重建:从基础知识到识别/重建方法!

039. (2.8) thoughts in the ward

968 edit distance
![[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics](/img/2d/9a7e88fb774984d061538e3ad4a96b.png)
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics

ICML 2022 | flowformer: task generic linear complexity transformer
随机推荐
@PathVariable
快过年了,心也懒了
First batch selected! Tencent security tianyufeng control has obtained the business security capability certification of the ICT Institute
Web开发小妙招:巧用ThreadLocal规避层层传值
ROS error: could not find a package configuration file provided by "move_base“
Replace Internet TV set-top box application through digital TV and broadband network
Study notes of grain Mall - phase I: Project Introduction
The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop
Aiko ai Frontier promotion (7.6)
After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
document.write()的用法-写入文本——修改样式、位置控制
It's almost the new year, and my heart is lazy
OneNote in-depth evaluation: using resources, plug-ins, templates
SDL2来源分析7:演出(SDL_RenderPresent())
What's the best way to get TFS to output each project to its own directory?
'class file has wrong version 52.0, should be 50.0' - class file has wrong version 52.0, should be 50.0
None of the strongest kings in the monitoring industry!
JS操作dom元素(一)——获取DOM节点的六种方式
[MySQL] trigger
Opencv learning example code 3.2.3 image binarization