Skip to content

Instantly share code, notes, and snippets.

@idefixcert
Created April 28, 2013 12:26
Show Gist options
  • Select an option

  • Save idefixcert/5476741 to your computer and use it in GitHub Desktop.

Select an option

Save idefixcert/5476741 to your computer and use it in GitHub Desktop.
Java DeepCopy via Serialization
public static <T> T deepCopy(T o) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(o);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
return (T) new ObjectInputStream(bais).readObject();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment