当前位置:网站首页>guava:Collections. The collection created by unmodifiablexxx is not immutable
guava:Collections. The collection created by unmodifiablexxx is not immutable
2022-07-06 21:33:00 【amadeus_ liu2】
One 、 Example
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);
}
}
Run program output :
Cannot pass Collections.unmodifiableXXX Create a reference to modify the object , But because of the original stringList It can be modified , and stringList1 and stringList Point to the same object ,stringList Modification will inevitably make stringList1 change .
边栏推荐
- 【论文解读】用于白内障分级/分类的机器学习技术
- Deployment of external server area and dual machine hot standby of firewall Foundation
- This year, Jianzhi Tencent
- Yuan Xiaolin: safety is not only a standard, but also Volvo's unchanging belief and pursuit
- 字符串的使用方法之startwith()-以XX开头、endsWith()-以XX结尾、trim()-删除两端空格
- HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
- KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
- 代理和反向代理
- 嵌入式开发的7大原罪
- JS get array subscript through array content
猜你喜欢
3D人脸重建:从基础知识到识别/重建方法!
ICML 2022 | flowformer: task generic linear complexity transformer
OneNote in-depth evaluation: using resources, plug-ins, templates
968 edit distance
【滑动窗口】第九届蓝桥杯省赛B组:日志统计
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
【力扣刷题】32. 最长有效括号
None of the strongest kings in the monitoring industry!
随机推荐
SDL2来源分析7:演出(SDL_RenderPresent())
Absolute primes (C language)
Deployment of external server area and dual machine hot standby of firewall Foundation
El table table - sortable sorting & disordered sorting when decimal and% appear
Yyds dry inventory run kubeedge official example_ Counter demo counter
968 edit distance
jvm:大对象在老年代的分配
袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求
Why does MySQL index fail? When do I use indexes?
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
This year, Jianzhi Tencent
20220211 failure - maximum amount of data supported by mongodb
C语言:#if、#def和#ifndef综合应用
Swagger UI tutorial API document artifact
What's the best way to get TFS to output each project to its own directory?
@Detailed differences among getmapping, @postmapping and @requestmapping, with actual combat code (all)
Seven original sins of embedded development
50个常用的Numpy函数解释,参数和使用示例
技术分享 | 抓包分析 TCP 协议
None of the strongest kings in the monitoring industry!