当前位置:网站首页>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发生变化。
边栏推荐
- Start the embedded room: system startup with limited resources
- Quick news: the flybook players' conference is held online; Wechat payment launched "education and training service toolbox"
- PHP saves session data to MySQL database
- Absolute primes (C language)
- Acdreamoj1110 (multiple backpacks)
- Ravendb starts -- document metadata
- Is it profitable to host an Olympic Games?
- js中,字符串和数组互转(一)——字符串转为数组的方法
- 对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
- 监控界的最强王者,没有之一!
猜你喜欢

The biggest pain point of traffic management - the resource utilization rate cannot go up

Data Lake (VIII): Iceberg data storage format

【力扣刷题】32. 最长有效括号

LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
![[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)](/img/1c/973f824f061d470a4079487d75f0d0.png)
[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)

3D人脸重建:从基础知识到识别/重建方法!
![[Li Kou brush questions] 32 Longest valid bracket](/img/51/1ce4f9e8517dba214ec82b6567c923.png)
[Li Kou brush questions] 32 Longest valid bracket

Is this the feeling of being spoiled by bytes?

防火墙基础之外网服务器区部署和双机热备

KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
随机推荐
JS get array subscript through array content
JS according to the Chinese Alphabet (province) or according to the English alphabet - Za sort &az sort
It's not my boast. You haven't used this fairy idea plug-in!
How do I remove duplicates from the list- How to remove duplicates from a list?
Word bag model and TF-IDF
@Detailed differences among getmapping, @postmapping and @requestmapping, with actual combat code (all)
Proxy and reverse proxy
Swagger UI tutorial API document artifact
@GetMapping、@PostMapping 和 @RequestMapping详细区别附实战代码(全)
Nodejs tutorial expressjs article quick start
Pat 1085 perfect sequence (25 points) perfect sequence
面试官:Redis中有序集合的内部实现方式是什么?
Hill | insert sort
js中,字符串和数组互转(一)——字符串转为数组的方法
Description of web function test
Replace Internet TV set-top box application through digital TV and broadband network
20220211 failure - maximum amount of data supported by mongodb
[MySQL] trigger
Caching strategies overview
袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求