用Clonable接口实现对象的克隆——浅拷贝和深拷贝 1. 浅拷贝2. 深拷贝 在Object类中提供了clone方法,用来是实现对象的克隆! 1. 浅拷贝
我们首先来尝试用clone方法去克隆一个Person对象
public class Person {public String name;public int age;publi…
先来看看JDK的解释: java.lang.Cloneable A class implements the Cloneable interface to indicate to the java.lang.Object.clone() method that it is legal for that method to make a field-for-field copy of instances of that class. Invoking Objects clo…