Eric Fowler
2015-04-29 04:19:17 UTC
Here is a super easy one for the panel: How do I create a duplicate of an
object?
scala> class C(val c:Int, var s:String)
defined class C
scala> val c = new C(1, "Hello")
c: C = ***@5d9b7a8a
scala> println(c.s)
Hello
scala> val b = c
b: C = ***@5d9b7a8a
scala> b.s = "Goodbye"
b.s: String = Goodbye
scala> println(c.s)
Goodbye
I want the last line to print 'Hello', not goobye: a memberwise copy into a
new object is desired.
object?
scala> class C(val c:Int, var s:String)
defined class C
scala> val c = new C(1, "Hello")
c: C = ***@5d9b7a8a
scala> println(c.s)
Hello
scala> val b = c
b: C = ***@5d9b7a8a
scala> b.s = "Goodbye"
b.s: String = Goodbye
scala> println(c.s)
Goodbye
I want the last line to print 'Hello', not goobye: a memberwise copy into a
new object is desired.
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.