clone() method in Java

前端 未结 5 993
再見小時候
再見小時候 2021-02-14 22:14

as I understood, the method clone() gives us the ability to copy object (no refernce) in Java. But I also read, that the copy is shallow. So what the point? Which a

5条回答
  •  孤城傲影
    2021-02-14 23:06

    A simple assignment will simply create an Alias for the object. With clone(), each attribute member will also be initialized in the clone Object. However, if the Attribute members are themselves have more objects contained within them, those will not not be copied.

提交回复
热议问题