<分区>
我是 Java 的新手,有人可以告诉我吗?是吗
浅拷贝
:复制原始类型和引用
深拷贝
:对象被递归拷贝
clone()
没有默认实现
标签 java
<分区>
我是 Java 的新手,有人可以告诉我吗?是吗
浅拷贝
:复制原始类型和引用
深拷贝
:对象被递归拷贝
clone()
没有默认实现
最佳答案
您可以查看 clone()
的文档:
The method
clone
for classObject
performs a specific cloning operation. First, if the class of this object does not implement the interfaceCloneable
, then aCloneNotSupportedException
is thrown. Note that all arrays are considered to implement the interfaceCloneable
and that the return type of the clone method of an array typeT[]
isT[]
whereT
is any reference or primitive type. Otherwise, this method creates a new instance of the class of this object and initializes all its fields with exactly the contents of the corresponding fields of this object, as if by assignment; the contents of the fields are not themselves cloned. Thus, this method performs a "shallow copy" of this object, not a "deep copy" operation.
关于java - 默认的 java.lang.Object.clone() 方法执行什么类型的复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18108414/