美文网首页
我们需要在自己的类中实现clone方法吗?

我们需要在自己的类中实现clone方法吗?

作者: 泰兰德的加长香蕉 | 来源:发表于2018-09-26 23:15 被阅读0次

  Should you implement clone in your own classes? If your clients need to make deep copies, then you probably should. Some authors feel that you should avoid clone altogether and instead implement another method for the same purpose. We agree that clone is rather awkward, but you’ll run into the same issues if you shift the responsibility to another method. At any rate, cloning is less common than you may think. Less than 5 percent of the classes in the standard library implement clone.

相关文章

网友评论

      本文标题:我们需要在自己的类中实现clone方法吗?

      本文链接:https://www.haomeiwen.com/subject/zhksoftx.html