Copy an object in Java

后端 未结 7 580
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 03:41

I have an object that I need to copy in Java. I need to create a copy and run some tests on it without changing the original object itself.

I assumed that I needed t

7条回答
  •  无人及你
    2020-12-09 04:18

    Joshua Bloch has some interesting things to say about cloneable. Depending on the size/construction of the object, I'd add a copy constructor to the object, or serialise/deserialise using one of the solutions mentioned above.

提交回复
热议问题