How to check “instanceof ” class in kotlin?

后端 未结 8 1571
有刺的猬
有刺的猬 2020-12-14 05:14

In kotlin class, I have method parameter as object (See kotlin doc here ) for class type T. As object I am passing different classes when I am calling metho

8条回答
  •  [愿得一人]
    2020-12-14 05:59

    You can use is:

    class B
    val a: A = A()
    if (a is A) { /* do something */ }
    when (a) {
      someValue -> { /* do something */ }
      is B -> { /* do something */ }
      else -> { /* do something */ }
    }
    

提交回复
热议问题