match

package com.bjsxt.scala

object Lesson_match {
  def main(args: Array[String]): Unit = {
    val tuple = (1,"hello",'c',1.0,true)
    val iter = tuple.productIterator
    while(iter.hasNext){
      val one = iter.next()
      MatchTest(one)
    }
  }
  
  def MatchTest(o:Any)=
    o match {
      case i:Int=>{println("type is Int")}
      case d:Double=>{println("typle is Double")}
      case 1=>{println("value is 1")}
      case 'c'=>{println("value is c")}
      case s:String=>{println("type is String")}
      case _=>{println("no match ... ")}
    }
  
  
}

  

猜你喜欢

转载自www.cnblogs.com/huiandong/p/9278284.html
今日推荐