edwardwongtl
09/19/2017, 8:39 AMval A.extVal get() = B(this)
Is there a way to not construct B every time I reference to A.extVal? Given that I don't own class A.marstran
09/19/2017, 9:06 AMlazy-delegate, but it didn't work because you don't have access to this inside the function you pass to it. I guess you could create your own version of the lazy-delegate that passes the receiver object as a parameter to the function though.marstran
09/19/2017, 9:07 AMmarstran
09/19/2017, 9:09 AMclass LazyExtension<V, T>(val f: V.() -> T) {
data class Result<T>(val t: T)
var result: Result<T>? = null
operator fun getValue(thisRef: V, property: kotlin.reflect.KProperty<*>): T {
return result?.t ?: Result(thisRef.f()).also {
result = it
}.t
}
}edwardwongtl
09/19/2017, 10:22 AMmarstran
09/19/2017, 10:49 AMtmp variable.ilya.gorbunov
09/19/2017, 10:52 AMmarstran
09/19/2017, 10:54 AMmarstran
09/19/2017, 10:58 AM