我學習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 –