0

Kotlin 怎样判断 instanceof class

leon created at7 years ago view count: 3478
report
回复
0

if (obj is ClassName)

7 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

7 years ago 回复

Recent search keywords