Given classes
sealed abstract class A
case class B(param: String) extends A
case class C(param: Int) extends A
trait Z {}
class Z1 extends Z {}
class Z2 extends Z {}
def zFor[T <: A : Manifest]: Option[Z] = {
val z = manifest[T].erasure
if (z == classOf[B]) {
Some(new Z1)
} else
if (z == classOf[C]) {
Some(new Z2)
} else {
None
}
}
I think the problem with pattern matching here is impossibility to build pattern matching table in the bytecode. Is there any workaround over this problem? May be I can use some Int generated in Manifest by compiler?