0
这是我曾尝试如何复制案例类对象?
sealed abstract class Tree
case class NewNode(left: Tree,center: Tree, right: Tree) extends Tree
我只是想复制整个对象
scala> val treeM = treeD.copy_
<console>:16: error: value copy_ is not a member of NewNode
val treeM = treeD.copy_
^
以上不工作
scala> val treeM = treeD.copy(_,_,_)
treeM: (Tree, Tree, Tree) => NewNode = <function3>
scala> println("Tree M == Tree D: %s" format (treeM == treeD).toString)
<console>:18: warning: (Tree, Tree, Tree) => NewNode and NewNode are unrelated: they will most likely never compare equal
println("Tree M == Tree D: %s" format (treeM == treeD).toString)
如何编写正确的对象副本?
你能解释一下为什么你想这样做吗? –