Slackbot
03/12/2019, 11:53 AMzsmb
03/12/2019, 1:05 PMisInitialized
property instead of a null check? Is it to allow for initialization to a nullable value? (since T
is allowed to be nullable)skoric
03/12/2019, 1:55 PMnull
. And then that initialization would happen every other time we reference it, since the value will again be null
. This won’t happen if used correctly but with boolean we keep the implementation very precise. If you check the Kotlin source, they don’t use isInitialized
but the property value is defined as Any
and it holds some predefined object (UNINITIALIZED_VALUE
), and then once it’s initialized, it will cast to T
(https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/kotlin/util/Lazy.kt#L76-L85). For the sake of simplicity, I used boolean value.