我想问一下因为我是相当新的,这是制作文档对象的深层副本的正确方法,我不知道我是否正确地实现了字段的复制。
package model;
public class Document implements Cloneable {
//fields
private String author;
private String date;
private double versionID;
private String contents;
public Document(String author,String date,double versionID,String contents) {
this.author=author;
this.date=date;
this.versionID=versionID;
this.contents=contents;
}
//getters-setters
}
//making the deep-copy clone all obj ref to Document
@Override
public Object clone() throws CloneNotSupportedException {
Document doc =(Document)super.clone();
doc.author=this.author;
doc.date=this.date;
doc.versionID=this.versionID;
doc.contents=this.contents;
return doc;
}
}