当前位置:网站首页>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发生变化。
边栏推荐
- document. Usage of write () - write text - modify style and position control
- VIM basic configuration and frequently used commands
- Quick access to video links at station B
- 967- letter combination of telephone number
- [redis design and implementation] part I: summary of redis data structure and objects
- js之遍历数组、字符串
- Acdreamoj1110 (multiple backpacks)
- Torch Cookbook
- Z function (extended KMP)
- The most comprehensive new database in the whole network, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, flying Book Multidimensional table, heipayun, Zhix
猜你喜欢

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

967- letter combination of telephone number

数据湖(八):Iceberg数据存储格式

2017 8th Blue Bridge Cup group a provincial tournament

愛可可AI前沿推介(7.6)

快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”

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

Study notes of grain Mall - phase I: Project Introduction

LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
![[MySQL] trigger](/img/b5/6df17eb254bbdb0aba422d08f13046.png)
[MySQL] trigger
随机推荐
PG basics -- Logical Structure Management (transaction)
JS get array subscript through array content
@GetMapping、@PostMapping 和 @RequestMapping详细区别附实战代码(全)
JS learning notes OO create suspicious objects
c#使用oracle存储过程获取结果集实例
Thinking about agile development
OneNote 深度评测:使用资源、插件、模版
C # use Oracle stored procedure to obtain result set instance
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
【mysql】触发器
OSPF multi zone configuration
One line by line explanation of the source code of anchor free series network yolox (a total of ten articles, you can change the network at will after reading it, if you won't complain to me)
20220211 failure - maximum amount of data supported by mongodb
Sdl2 source analysis 7: performance (sdl_renderpresent())
Opencv learning example code 3.2.3 image binarization
Three schemes of SVM to realize multi classification
2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
JS operation DOM element (I) -- six ways to obtain DOM nodes
R language for text mining Part4 text classification
Four common ways and performance comparison of ArrayList de duplication (jmh performance analysis)