https://kotlinlang.org logo
#announcements
Title
# announcements
s

spragg

09/10/2017, 11:35 PM
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

karelpeeters

09/10/2017, 11:36 PM
If you need that
lateinit
is not really the right tool anymore, just use a nullable instead.
s

spragg

09/10/2017, 11:40 PM
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

russhwolf

09/11/2017, 12:31 AM
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

Dalinar

09/11/2017, 12:55 AM
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