当前位置:网站首页>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发生变化。
边栏推荐
- 在最长的距离二叉树结点
- Deployment of external server area and dual machine hot standby of firewall Foundation
- Quick news: the flybook players' conference is held online; Wechat payment launched "education and training service toolbox"
- Pat 1085 perfect sequence (25 points) perfect sequence
- It's not my boast. You haven't used this fairy idea plug-in!
- 2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
- Start the embedded room: system startup with limited resources
- The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop
- JS according to the Chinese Alphabet (province) or according to the English alphabet - Za sort &az sort
- 20220211 failure - maximum amount of data supported by mongodb
猜你喜欢
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
Is it profitable to host an Olympic Games?
[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
跨分片方案 总结
After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
Aike AI frontier promotion (7.6)
039. (2.8) thoughts in the ward
[Li Kou brush questions] 32 Longest valid bracket
随机推荐
首批入选!腾讯安全天御风控获信通院业务安全能力认证
Ravendb starts -- document metadata
document. Usage of write () - write text - modify style and position control
【论文解读】用于白内障分级/分类的机器学习技术
@GetMapping、@PostMapping 和 @RequestMapping详细区别附实战代码(全)
Fzu 1686 dragon mystery repeated coverage
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
MySQL - 事务(Transaction)详解
PG basics -- Logical Structure Management (transaction)
Set up a time server
对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
【力扣刷题】32. 最长有效括号
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
b站视频链接快速获取
document.write()的用法-写入文本——修改样式、位置控制
技术分享 | 抓包分析 TCP 协议
Acdreamoj1110 (multiple backpacks)
Redistemplate common collection instructions opsforzset (VI)
JS操作dom元素(一)——获取DOM节点的六种方式
First batch selected! Tencent security tianyufeng control has obtained the business security capability certification of the ICT Institute