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 ... ")}
}
}

浙公网安备 33010602011771号