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)
如何編寫正確的對象副本?
你能解釋一下爲什麼你想這樣做嗎? –