Skip to content

Instantly share code, notes, and snippets.

@tralamazza
Created November 30, 2011 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tralamazza/4409b8562ac24fc042b0 to your computer and use it in GitHub Desktop.
Save tralamazza/4409b8562ac24fc042b0 to your computer and use it in GitHub Desktop.
// http://stackoverflow.com/a/1270941/566999
def deepCopy[A](a: A)(implicit m: reflect.Manifest[A]): A = util.Marshal.load[A](util.Marshal.dump(a))
case class Foo(x: Int)
val o1 = new Foo(10)
val o2 = deepCopy(o1)
/* scala> val o2 = deepCopy(o1)
java.lang.ClassNotFoundException: Foo
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
...
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment