尝试重构和改进这种模式匹配:
abstract class SuperClass
case class Foo() extends SuperClass
case class Bar() extends SuperClass
def getTheClass(param:String)={
Class.forName(param)
}
val bazz = getTheClass(classOf[Foo].getName)
bazz match{
case b if b == classOf[Bar] => "I am Bar"
case f if f == classOf[Foo] => "I am Foo"
}
没有守卫有优雅的方式吗?