How to make a deep copy of a Java object without using serialization?

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

+5
source share
1 answer

You can use the Java Deep-Cloning Library to create deep copies of objects. This is really useful when you cannot (or don't want) to make your classes serializable. Use is straightforward:

 Cloner cloner = new Cloner(); MyClass clone = cloner.deepClone(o); // clone is a deep-clone of o 
+3
source

Source: https://habr.com/ru/post/1201022/


All Articles