0

我正在关注 Coursera Scala 类的视频 3.1,但无法让我的 Scala 工作表识别出确实为 Empty 类定义了 contains 方法:

package objsets

abstract class IntSet {
  def incl(x:Int): IntSet
  def contains(x:Int): Boolean
}


class Empty extends IntSet {
def contains(x: Int): Boolean = false
def incl(x: Int): IntSet = new NonEmpty(x, new Empty, new Empty)
}

class NonEmpty (elem: Int, left: IntSet, right: IntSet) extends IntSet {
    def contains(x: Int):Boolean =
        if (x < elem) left contains x
        else if (x > elem) right contains x
        else true

    def incl(x:Int):IntSet =
        if (x < elem) new NonEmpty(elem, left incl x,right)
        else if (x > elem) new NonEmpty(elem, left, right incl x)
        else this
}

object Video1 {
    val empty = new Empty
    empty.contains(2)
}

在对象 Video1 的末尾,当我调用 .contains() 时,我在 Scala IDE 工作表中收到以下错误:

NoSuchMethodError: objsets.Empty.contains(I)Z

4

0 回答 0