匹配前提必须是 case 中的子类或者父类
object Test3{
def main(args: Array[String]): Unit = {
def matchClass(x:Any):String={
x match {
case i:Array[Int] => "array"
case i:List[Int] => "list"
case _ => "Nothing"
}
}
println(matchClass(Array(1, 2, 3)))
println(matchClass(List(1, 2, 3)))
}
}