This is a straight forward question but I cannot find an answer. Is there a way to be notified when a lateinit var
has been initialised in Kotlin?
I know I can check if it has been initialised with this::coolvar.isInitialized
but this is not the same.
Thank you
lateinit var
works well only in the simplest cases when uninitialized value doesn't make sense in the context of the app, such as dependency injection or late initialization inonCreate()
.What you need is a property delegate with a particular behavior. Take a look at
Delegates.observable
: