https://kotlinlang.org logo
Title
o

oday

04/15/2019, 3:29 PM
is it “hacky” to use ::isInitialized?
w

wbertan

04/15/2019, 3:44 PM
We use it... But, everytime I see that code, it looks wrong, looks like I missed something in the architecture of it to not have the need of that.... But, I use that only once, and pushed far, far away in the code (it is a "Wrapper" to a 3rd party library) <-- because of that I decide to "keep" it, if it was in other places and in our business logic classes, probably I will refactor to not need it.
k

kevinmost

04/15/2019, 5:17 PM
I don't think so. It's equivalent to doing a null-check on a nullable variable, but once this one changes, you know that the variable will stay non-null. It's a lot like MonotonicNonNull in Checker (https://checkerframework.org/api/org/checkerframework/checker/nullness/qual/MonotonicNonNull.html)
stronger guarantee than Nullable
k

karelpeeters

04/15/2019, 5:33 PM
If you do
::isInitialized
in multiple places imo it's just better to switch to nullable, it's so easy to forget otherwise. If you only check it it one specific place and use the variable normally in many other places I think it's fine.
☝️ 1
o

oday

04/16/2019, 1:44 PM
great, thanks guys