what I want to achieve in here is to compare a string with a value of an enum
first, I tried it using if
object FooType extends Enumeration {
type FooType = Value
val FooA = Value("FA")
val FooB = Value("FB")
}
val x = "FA"
if (x == FooType.FooA) //Does not match
println("success using if without toString")
if (x == FooType.FooA.toString) //match
println("success using if with toString")
println(FooType.FooA) //will print into "FA"
at least, it still working well when I compare it to the enum with toString method. but if I change it to a match case, it would turn into an error instead
x match {
case FooType.FooA.toString => println("success using match")
}
ScalaFiddle.scala:19: error: stable identifier required, but ScalaFiddle.this.FooType.FooA.toString found.
case FooType.FooA.toString => println("success using match")
^
is there any way to achieve this by using match case?