gpt4 book ai didi

nullpointerexception - Kotlin NullPointerException 发生

转载 作者:行者123 更新时间:2023-12-04 08:23:38 25 4
gpt4 key购买 nike

我是新来的 , 当我开始 Null Safety 时,我对下面的情况感到困惑.

There's some data inconsistency with regard to initialization (an uninitialized this available in a constructor is used somewhere).



谁能更详细地描述一下情况?

最佳答案

示例改编自 Kotlin discussion on exactly this :

class Foo {
val c: String // Non-nullable

init {
bar()
c = "" // Initialised for the first time here
}

fun bar() {
println(c.length) // Oh dear
}
}

fun main(args: Array<String>) {
Foo()
}

关于nullpointerexception - Kotlin NullPointerException 发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44529375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com