1.实现克隆接口
public class Prototype implements Cloneable { public Prototype(String name) { this.name = name; } private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } @Override protected Object clone() throws CloneNotSupportedException { return super.clone(); } }
2.调用:地址不同
Prototype p1 = new Prototype("test"); Prototype p2 = (Prototype) p1.clone(); System.out.println(p1.toString()); System.out.println(p2.toString()); com.jd.xq.Prototype@2f0e140b com.jd.xq.Prototype@2f0e140b
3.浅克隆、深克隆----是否需要克隆类里面的对象
https://blog.csdn.net/zz_15127160921/article/details/81282140