比方说,我有一个Tree
对象,其中包含2个成员对象right
和left
。检查会员是否为
检查tree
的“右”和“左”字段是否为零的常用/正确方法是什么?
def count(tree: Tree, acc: Int) : Int = tree match {
case tree .right != Nil && tree .left != Nil => countLeftAndRight(...)
case tree .right != Nil => countOnlyRight(...)
case tree .left != Nil => countOnlyLeft(...)
_ => acc
}
什么是'x'?您的匹配块似乎不合法。 – pedrofurla
对不起 - 我更新为'tree',而不是'x' –