枚举值在匹配/大小写表达式中似乎失败。这是工作表中发生的情况。Scala枚举类型匹配失败/ case
object EnumType extends Enumeration {
type EnumType = Value
val a, b = Value
}
import EnumType._
val x: EnumType = b //> x : ... .EnumType.EnumType = b
x match {
case a => "a"
case b => "b"
} //> res0: String = a
if (x == a) "a" else "b" //> res1: String = b
发生了什么事?谢谢。
你应该得到一个警告,第二次'case'永远无法匹配,对不对? –
.scala文件中的相同代码会生成警告,但不会出现在工作表中。 – RussAbbott