Reputation: 1314
Is it possible to make a deep copy/clone of a Java object without using serialization ? If so then how ?
Upvotes: 6
Views: 5907
Reputation: 31504
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
Upvotes: 4