当我尝试在 Eclipse 中运行以下代码时,“作为 Scala 应用程序运行”未显示。主要方法定义正确吗?
package week4
class Nil[T] extends List[T] {
def isEmpty: Boolean = true
def head: Nothing = throw new NoSuchElementException("Nil.head")
def tail: Nothing = throw new NoSuchElementException("Nil.tail")
}
trait List[T] {
def isEmpty: Boolean
def head: T
def tail: List[T]
}
class Cons[T](val head: T, val tail: List[T]) extends List[T]{
def isEmpty = false
}
object List {
def apply[T](x1: T, x2: T): List[T] = new Cons(x1, new Cons(x2, new Nil))
def apply[T]() = new Nil
def main(args:Array[String]) = {
println(List(1,4))
}
}