您的位置:首页 > 其它

云星数据---Scala实战系列(精品版)】:Scala入门教程038-Scala实战源码-Scala match语句03 类型匹配

2017-11-28 10:30 666 查看

Scala match case 类型匹配

package scala_learn.demo09_Match

/**
* Created by liguohua on 2017/3/1.
*/
class O3_MatchDemo {

}

object O3_MatchDemo {
def main(args: Array[String]) {
test("2")
}

def test(obj: Any): Unit = {
//匹配可以进行类型判定
val rs = obj match {
case i: Int => "Int type"
case s: String => "String type"
case _ => "other type"
}
println(rs)
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐