java - 默认的 java.lang.Object.clone() 方法执行什么类型的复制

标签 java

<分区>

我是 Java 的新手,有人可以告诉我吗?是吗

浅拷贝:复制原始类型和引用

深拷贝:对象被递归拷贝

clone() 没有默认实现

最佳答案

您可以查看 clone() 的文档:

The method clone for class Object performs a specific cloning operation. First, if the class of this object does not implement the interface Cloneable, then a CloneNotSupportedException is thrown. Note that all arrays are considered to implement the interface Cloneable and that the return type of the clone method of an array type T[] is T[] where T 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/

相关文章:

java - Android OnPreferenceClickListener

java - 如何临时创建一个没有任何文件位置的文本文件并在运行时在 Spring Boot 中作为响应发送?

java - JMS Bridge 现有队列消息

java - 在 Jsoup 中获取响应代码时,HttpConnection 无法转换为 Connection$Response

java - 找到对应于 k-large 元素的值

JAVA - 扫描仪获取用户输入

java - 如何通过引用 Java 中包含数组的 HashMap 来向数组添加值?

Java protected 字段与公共(public) getter

java - Hibernate的SQLQueryexecuteUpdate函数启动,但没有完全执行

java - 无需重新启动即可生成 Java 线程转储。