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

本文介绍了一个简单的 Scala 程序示例,演示了如何使用 match 表达式来进行类型判定,包括对 Int 和 String 类型的具体匹配以及对其他类型的默认匹配。
3万+

被折叠的 条评论
为什么被折叠?



