定义方法时的NoMethodError

时间:2013-04-17 13:56:19

标签: scala

我正在关注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

0 个答案:

没有答案