简体   繁体   English

是否有必要为不可变对象制作深层副本

[英]Is it necessary to make a deep copy for an immutable object

是否有理由对不可变对象的引用数组进行深层复制?

No. A (shallow) copy of the array will have all the references to the immutable objects at the time of the copying. 否。数组的(浅)副本将在复制时具有对不可变对象的所有引用。 No matter what happens with the original array, the copy will always have the same state as at the time of the copying. 无论原始数组发生什么,副本将始终具有与复制时相同的状态。

Deep copying of immutable objects (or arrays of immutable objects) would make sense only if you wanted to have two equal but distinct immutable objects. 只有当你想拥有两个相同但不同的不可变对象时,深层复制不可变对象(或不可变对象数组)才有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM