Why is #clone() not in the Cloneable interface?

后端 未结 3 2027
盖世英雄少女心
盖世英雄少女心 2021-01-31 20:13

I was reading up on performing a deep-copy of an array correctly, however I was confused about how the #clone() is implemented. It is a member of the java.lan

3条回答
  •  -上瘾入骨i
    2021-01-31 20:35

    To deal with creating the clone and basic field copying, clone needs to inherit a method implementation. A Cloneable class can appear anywhere in the hierarchy, and may need to extend a specific superclass to do its primary job. The only superclass from which all possible Cloneable classes can inherit implementation is Object.

    Cloning was defined long before generics.

提交回复
热议问题