public class Table implements Cloneable{
private Point center;
public void setCenter;
public Point getCenter(){
return center;
}
public Object clone()throws CloneNotSupportedException{
Table table=(Table)super.clone();
if(this.center!=null){
table.center=(Point)center.clone();
}
return table;
}
}
本文介绍了一个实现了深拷贝功能的Table类。该类通过实现Cloneable接口并覆盖clone方法来支持对象的克隆。当对象包含引用类型成员变量时,如Point类型的center,会进一步调用该成员变量的clone方法来确保深拷贝的实现。

被折叠的 条评论
为什么被折叠?



