For example in Properties/Lazy property/src/Task.kt the solution:
class LazyProperty(val initializer: () -> Int) {
var value: Int? = null
val lazy: Int
get() {
if (value == null) {
value = initializer()
}
return value!!
}
}
Would be safer using:
class LazyProperty(val initializer: () -> Int) {
private var value: Int? = null
val lazy: Int
get() = value ?: initializer().also { value = it }
}