Object Clone Shallow copy doesn't change variable

后端 未结 3 1347
生来不讨喜
生来不讨喜 2021-01-15 11:25

I tried to clone an object and change member functions of new clonned object. If it is shallow copy and according to wiki page, shallow copy and original object point to sam

3条回答
  •  轮回少年
    2021-01-15 12:09

    Shallow copy of obj1 creates another instance obj2 of your CloneExample class (obj1!=obj2). They don't share value members.

    But if our class contained a reference type, for example java.util.Date, then changing it's value would be reflected in both object if they shared reference to that java.util.Date.

    In Java, what is a shallow copy?

提交回复
热议问题