How to make deep copy of java object without using serialization ?

橙三吉。 提交于 2019-12-01 04:13:16

问题


Is it possible to make a deep copy/clone of a Java object without using serialization ? If so then how ?


回答1:


You could use the Java Deep-Cloning Library to make deep copies of objects. It is really useful when you can't (or don't want) to make your classes serializable. The use is straight-forward:

Cloner cloner = new Cloner();

MyClass clone = cloner.deepClone(o);
// clone is a deep-clone of o


来源:https://stackoverflow.com/questions/25472281/how-to-make-deep-copy-of-java-object-without-using-serialization

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!