In Java we can do switch(value) {case(x): // do something;}
In Scala, we can do something similar with case match expressions:
val a = 1
a match {
case 1 => 1
case 2 => 2
} // 1
However, it doesn't work with a value of type reflect.runtime.universe.Type
.
val tpe = typeOf[Int]
tpe match {
case typeOf[Int] => 1
case typeOf[Option[Any]] => 2
}
error: not found: type typeOf
case typeOf[Int] => 1
^
Instead, I have to do this:
if (tpe =:= typeOf[Int]) {...}
else if (tpe =:= Option[Any]) {...}
Is there a chance to use case match expression here?