入门语句:
package cn.sendohhadoop.scala
/**
* Created by sendoh on 2015/2/3.
*/
class Basic4 {
}
object Basic4 extends App{
val value = 1
val result = value match{
case 1 => "one"
case 2 => "two"
case _ => "some other number"
}
val result2 = value match{
case i if i == 1 => "one"
case i if i == 2 => "two"
case _ => "some other number"
}
println("result of match is :" + result)
println("result2 of match is :" + result2)
def t(obj : Any) = obj match{
case x : Int => println("Int")
case s : String => println("String")
case _ => println("unknown type")
}
//case匹配类型
t(1)
//t("1")
//t("12kk")
}