There’s no variable with name lateinitVar in your code, thus the error. Look at the example again:
this::lateinitVar.isInitialized
There’s a variable lateinitVar defined in this, which the function is called on. The code snippet in the example can be expanded (little plus sign at the beginning of the listing) and looks as follows:
class Foo {
lateinit var lateinitVar: String
fun initializationLogic() {
println("isInitialized before assignment: " + this::lateinitVar.isInitialized)
lateinitVar = "value"
println("isInitialized after assignment: " + this::lateinitVar.isInitialized)
}
}
This might make it more clear.
Also, be aware that lateinit can’t be applied to val but only var.