LoginSignup
0
0

More than 5 years have passed since last update.

【教えて】traitとcase classのcopy

Posted at

case class の copy メソッドで作られた新しいオブジェクトは、traitの version の値を引き継ぎませんが、Scala 2.10ではこれを引き継ぐようにできるのでしょうか?

trait Version {
    var version = 1
}

case class Item(name : String) extends Version

val foo = Item("Foo")
foo.version = 2

println(foo)
println(foo.version) // 2

val bar = foo.copy()
println(bar.version) // 1 (ここが2になるようにしたい)
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0