0

Kotlin 怎样判断 instanceof class

leon created at6 years ago view count: 3468
report
回复
0

if (obj is ClassName)

6 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

6 years ago 回复

相关搜索关键词

Recent search keywords