when
fun getColor(color :Color){when(color){Color.BLUE -> println("this is blue")Color.RED -> println("this is RED")Color.GREEN -> println("this is GREEN")Color.BLUE2 ,Color.RED2 -> println("this is blue or red")}}// main 调用getColor(Color.GREEN)
is
fun GetNumber(x: Any) = when (x) {//kotlin中所有类都有一个共同的父类: Any
is String -> {//如果x是String类型,执行该代码块
}
is Int -> {
//如果x是Int类型,执行该代码块
}
else -> false
}
javaClass
var args:Int =3
println(args.javaClass)
println(args::class.java)
输出
int
int
