是否有一种不那么复杂的方法来查找枚举值的前任和后继?
object E extends Enumeration {
val W, X, Y, Z = Value
}
def succ(a: E.Value) : E.Value = {
val arr = E.values.toArray
return arr(a.id + 1)
}
scala> succ(E.W)
res17: E.Value = X
scala> succ(E.Y)
res18: E.Value = Z