可能重复:
Clone() vs Copy constructor- which is recommended in java
在下面的示例中,useClone
和copyConstrutor
创建的对象之间是否存在差异?
class A implements Cloneable{
int data = 9;
public A useClone() throws CloneNotSupportedException {
return (A)super.clone();
}
public A copyConstrutor() {
A o = new A();
o.data = this.data;
return o;
}
}