原型模式 深拷贝 重写clone方式

public class Citation implements Cloneable{
    private String name;
    private Student student;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Citation clone = (Citation) super.clone();
        clone.student = (Student) this.student.clone();
        return clone;
    }
}
public class Student implements Cloneable{
    private String name;
    private int age;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

 

posted on 2022-04-16 17:29  金满仓  阅读(36)  评论(0编辑  收藏  举报

导航