hello, it seems that the lateinit isInitialized ca...
# announcements
h
hello, it seems that the lateinit isInitialized can only be called from inside the class, is it a bug or something?
Copy code
class AClass {
    lateinit var aLateInit: String

    fun isInit() = this::aLateInit.isInitialized // OK
}

val obj1 = AClass()
val isInit = obj1::aLateInit.isInitialized // Not Compile
e
By design to preserve encapsulation.
e
ahhhh. interesting. good to know.
makes sense.
h
thank you 🙂
e
is that a compiler/language special case? doesn’t seem to be anything in the source for lazy about that.
h
I think if the property
aLateInit
is public, it should be able to check its initialization state publicly
e
You can always declare a separate public property for that if that is you intent.
h
yes, in fact the
fun isInit()
above is ok for my intent. I'm just a bit curious about the design decision to prohibit the direct access in the first place.