Skip to content

Instantly share code, notes, and snippets.

@codahale
Created March 12, 2010 19:48
Show Gist options
  • Select an option

  • Save codahale/330703 to your computer and use it in GitHub Desktop.

Select an option

Save codahale/330703 to your computer and use it in GitHub Desktop.
scala> object Thing1 {
| var things = 0
| }
defined module Thing1
scala> class Thing1 {
| Thing1.things +=1
| }
defined class Thing1
scala> object Thing2 {
| var things = 0
| }
defined module Thing2
scala> class Thing2 {
| Thing2.things += 1
| }
defined class Thing2
scala> case class Combo(t1: Thing1, t2: Thing2)
defined class Combo
scala> val c1 = Combo(new Thing1, new Thing2)
c1: Combo = Combo(Thing1@5b55c5eb,Thing2@5c34f625)
scala> Thing1.things
res0: Int = 1
scala> Thing2.things
res1: Int = 1
scala> val c2 = c1.copy(t2 = new Thing2)
c2: Combo = Combo(Thing1@5b55c5eb,Thing2@7525c6bd)
scala> Thing1.things
res2: Int = 1
scala> Thing2.things
res3: Int = 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment