I have multiple enum objects as follows (these are just examples):
object Status extends Enumeration {
val Pending, Done = Value
}
object Gender extends Enumeration {
val Female, Male, Other = Value
}
...
And, I want to match any object extending Enumeration. This one works:
def func(anyVal: Any): String = anyVal match {
case strVal: String => "This is a String"
case status: Status.Value => "This is an Enumeration"
case gender: Gender.Value => "This is an Enumeration"
...
}
However, I don't need to match enums separately. Something like this would be great:
def func(anyVal: Any): String = anyVal match {
case strVal: String => "This is a String"
case e: Enumeration.Value => "This is an Enumeration"
}
But, this doesn't work. Do you have any idea?