Created
April 28, 2013 12:26
-
-
Save idefixcert/5476741 to your computer and use it in GitHub Desktop.
Java DeepCopy via Serialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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