scala 样例类的模式匹配

package Demo001.scala02

object CaseDemo extends App {

  //样例类的模式匹配

  show(1)
  show(true)
  show(Demo("s",1))
  show(Demo("hhhh",23232))
  show(true,"hhhhh",1234567)


  case class Demo(x:String,y:Int)//样例类

  def show(x:Any) =x match {

    case x:Int => println("类型匹配")
    case x:Boolean =>println("布尔类型的匹配")
    case Demo("s",1)=>println("匹配样例类的实例")
    case Demo(a:String,b:Int) =>println("匹配样例类")
    case _ =>println("everything is nothing")

  }
}

你可能感兴趣的:(scala)