Scala中的类型不匹配
我在代码的最后一行有类型不匹配Scala中的类型不匹配,scala,types,mismatch,Scala,Types,Mismatch,我在代码的最后一行有类型不匹配 def balance(chars: List[Char]): Boolean = { def f(chars: List[Char], count: Int) :Boolean= if(chars.isEmpty) {(count==0)} else if (chars.head == '(') f(chars.tail,count+1) else if(chars.head == ')') f(chars.tail,cou
def balance(chars: List[Char]): Boolean = {
def f(chars: List[Char], count: Int) :Boolean=
if(chars.isEmpty) {(count==0)}
else if (chars.head == '(') f(chars.tail,count+1)
else if(chars.head == ')') f(chars.tail,count-1)
else f(chars.tail,count)
} //Type mismatch; found: unit required Boolean
balance
期望Boolean
作为返回值,但您只定义了f
,在balance
中没有做任何其他操作。缺少的可能是f(chars,0)
作为balance
中的最后一条语句,您是否正确粘贴和复制了它?这没有多大意义。balance
期望Boolean
作为返回值,但您只定义了f
,在balance
@VictorMoroz中没有做任何其他操作。您应该在下面详细说明这一点作为答案,因为它肯定是正确的。请参阅答案,情况完全相同。