Reputation: 30676
I'm new to kotlin, I'm confused the situation at below when I starting to Null Safety.
There's some data inconsistency with regard to initialization (an uninitialized this available in a constructor is used somewhere).
Could anyone describe the situation more in detailed?
Upvotes: 4
Views: 1987
Reputation: 272467
Example adapted from a 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()
}
Upvotes: 5