在Kotlin中,处理可空值、引用或转换这些值的惯用方法是什么?
Xyz?Xyz
val something: Xyz? = createPossiblyNullXyz()something.foo() // Error: "Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Xyz?"
val something: Xyz? = createPossiblyNullXyz()if (something != null) {
something.foo() }nullifnullget()null
val map = mapOf("a" to 65,"b" to 66,"c" to 67)val something = map.get("a")something.toLong()
// Error: "Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Int?"get()Int?
慕虎7371278
达令说
随时随地看视频慕课网APP