Java clone() method

前端 未结 3 1295
慢半拍i
慢半拍i 2021-01-13 18:45

I read Effective Java by J.Bloch and here was wrote:

If you design a class for inheritance, be aware that if you choose not to provide a well-behave

3条回答
  •  孤独总比滥情好
    2021-01-13 19:39

    Cloneable and clone() are pretty much deprecated, so it doesn't matter anyway. However, since clone() is always supposed to call super.clone(), if a superclass implements it wrong, the subclass won't be able to fix it either.

    It has nothing to do with not being able to override clone(), it just won't result in a correct implementation.

提交回复
热议问题