java 中的克隆方法与复制构造函数。哪一个是正确的解决方案。每个案例在哪里使用?
最佳答案
克隆已损坏,请勿使用。
THE CLONE METHOD of the Object class is a somewhat magical method that does what no pure Java method could ever do: It produces an identical copy of its object. It has been present in the primordial Object superclass since the Beta-release days of the Java compiler*; and it, like all ancient magic, requires the appropriate incantation to prevent the spell from unexpectedly backfiring
首选复制对象的方法
Foo copyFoo (Foo foo){
Foo f = new Foo();
//for all properties in FOo
f.set(foo.get());
return f;
}
阅读更多 http://adtmag.com/articles/2000/01/18/effective-javaeffective-cloning.aspx
关于java - Clone() vs Copy constructor - 在java中推荐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2427883/