How to check “instanceof ” class in kotlin?
问题 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 method. In Java we can able to compare class using instanceof of object which class it is. So I want to check and compare at runtime which Class it is? How can I check instanceof class in kotlin? 回答1: Use is . if (myInstance is String) { ... } or the reverse !is if (myInstance !is String) { ... } 回答2: Combining when and is : when (x) { is Int