0
我知道這個問題很簡單,但因爲我是斯卡拉的新來者,我無法弄清楚。下面是我的示例代碼:錯誤的停止語句聲明後定義對象
package datastructure
sealed trait List[+A]
case object Nil extends List[Nothing]
case class Cons[+A](head: A, tails: List[A]) extends List[A]
object List {
def sum(ints: List[Int]): Int = ints match {
case Nil => 0
case Cons(x, xs) => x + sum(xs)
}
def product(ds: List[Double]): Double = ds match {
case Nil => 1.0
case Cons(x, xs) => x * product(xs)
}
}
var a: Int = 3
我不知道,我總是在最後一行滿足follwing錯誤:
錯stop語句聲明
你不能在對象或類外聲明一個var。 – puhlen
我正在研究scala工作表。所以斯卡拉仍然阻止我這樣做? –