0

Kotlin 怎样判断 instanceof class

leon created at5 years ago view count: 3248
report
回复
0

if (obj is ClassName)

5 years ago 回复
0
neo #
when in doubt, use brute force
if (obj is String) {
    print(obj.length)
}

if (obj !is String) { // same as !(obj is String)
    print("Not a String")
}
else {
    print(obj.length)
}

https://kotlinlang.org/docs/reference/typecasts.html

5 years ago 回复

相关搜索关键词

Recent search keywords