关于clone的问题
我定义了 两个类 A , B
class A implements cloneable{
int i=1;
B b = new B();
public Object Clone(){
A result = (A)super.clone();
return result;
}
}
class B implements cloneable{
int j=2;
A a = new A();
public Object clone(){
B result =(B)super.clone();
return result;
}
}
想做深拷贝,上面肯定有问题,会循环调用clone而导致overflow的错误。
所以望各位高手给予指点,这样相互含有对象的情况应该如何做深拷贝,先谢谢了!