Copy an object in Java

后端 未结 7 566
伪装坚强ぢ
伪装坚强ぢ 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:03

    You can use org.apache.commons.lang3.SerializationUtils class for object cloning, - Class should implement Serializable interface.

    • ClassName copyobject = SerializationUtils.clone(classobjectTocopy)

    SerializationUtils.clone is also supported on Google App Engine instance

提交回复
热议问题