I’ve been searching. Is there a way to determine i...
# announcements
s
I’ve been searching. Is there a way to determine if a
lateinit var
is initialised without using it and catching the exception? or am I going to have to change it to a nullable ?
k
If you need that
lateinit
is not really the right tool anymore, just use a nullable instead.
s
Yep. That is what I am thinking. The situation is that I have a fragment with a webview and I need to load the webview only when it becomes visible. Unfortunately the best place for me to do that is in
setUserVisibleHint
but that is getting triggered before
onCreateView
. Thanks for the reply
r
I'd generally agree that you shouldn't be using
lateinit
for this, especially in your case because you're initializing in a somewhat unusual location. But see also https://youtrack.jetbrains.com/issue/KT-9327 if you do want the ability to check initialization of
lateinit
properties.
d
personally I wouldn't mind having this ability, I don't need it very often but would be nice
but what I do need more often but apparently jetbrains thinks it is a rare-use scenario (so not likely to happen I guess), is the ability to access a
this@lambda
. You can still work around it but it's a bit "ugly" - I really needed often in my JS code but in regular JVM Kotlin I also run into it once in a while