我学习Scala的个人兴趣,我通过以下的返回值困惑:关于斯卡拉* =运算符的返回值
var t : Long = 1
def product(s:String):Long = {
if(s.length > 1) t *= product(s.tail)
else t *= s.toLong
}
这是一个递归函数,但是编译器高大我有两个错误:
<console>:13: error: type mismatch;
found : Unit
required: Long
if(s.length > 1) t *= product(s.tail)
^
<console>:14: error: type mismatch;
found : Unit
required: Long
else t *= s.toLong
^
和在scala-doc中,我找不到def * = in Long。
什么是't'?它在哪里定义? – dhg
对不起var t:长= 1 –