adn.911
adn.911

Reputation: 1314

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

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

Upvotes: 6

Views: 5907

Answers (1)

enrico.bacis
enrico.bacis

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

Related Questions