java deep clone vs shallow clone

Java allows us to clone an object, usually used in decorator and prototype patterns. So what is a deep clone and what is a shallow clone.

  [Shallow clone], usually just copy the cloned instance, but other sub-objects in it are shared.

  [Deep clone], when cloning, it will copy the references of its sub-objects, and all the variables and sub-objects in it are additionally copied.
  
Original link:
https://www.cnblogs.com/xing901022/p/4051097.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325753015&siteId=291194637