如果需要复制一个对象,提供类似下面这种方法似乎是个不错的选择

Foo copyFoo (Foo foo){
  Foo f = new Foo();
  //for all properties in FOo
  f.set(foo.get());
  return f;
}

Effective Java,第11条有关于clone的讨论

 

http://stackoverflow.com/questions/2427883/clone-vs-copy-constructor-which-is-recommended-in-java

http://www.xenoveritas.org/blog/xeno/java_copy_constructors_and_clone 作者表示两者都不好

http://adtmag.com/articles/2000/01/18/effective-javaeffective-cloning.aspx

相关文章:

  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2021-12-13
猜你喜欢
  • 2022-12-23
  • 2021-07-01
  • 2021-10-16
  • 2021-07-06
  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案