when

  1. fun getColor(color :Color){
  2. when(color){
  3. Color.BLUE -> println("this is blue")
  4. Color.RED -> println("this is RED")
  5. Color.GREEN -> println("this is GREEN")
  6. Color.BLUE2 ,Color.RED2 -> println("this is blue or red")
  7. }
  8. }
  9. // main 调用
  10. 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