Scala枚举类型不匹配

时间:2016-01-19 20:22:44

标签: enums scala-2.10

我一直在scala 2.10.4环境中工作,我遇到了一个奇怪的错误,编码如下:

object TestTypes extends Enumeration {
    type TestTypes = Value
    val Test,
        Blah,
        Blah2 = Value
}

def printStuff(v: TestTypes.Value) = {
    println(v)
}


val v = TestTypes(1)
printStuff(v)

我得到的错误如下:

<console>:81: error: type mismatch;
 found   : TestTypes.Value
 required: TestTypes.Value
              printStuff(v)
                         ^

但我真的无法弄清楚为什么会出现这种错误。我无法升级scala版本(虽然我已经检查过,但这段代码在2.11.7中有效)。有没有人知道为什么会出现这种错误,如果有办法可以更好?

0 个答案:

没有答案
相关问题