lazy
calls initializer
function when it is accessed first time and then stores the value returned by the initializer
to return that value on successive accesses.
An instance of Lazy
is capable of storing exactly one value. When you delegate extension property to a Lazy
instance, you're getting a single instance of Lazy
serving getValue
requests from all instances of the receiver type, in your case it's Activity
. This results in Lazy
computing value only for first Activity
and using that value on all subsequent calls for other instances of Activity
.
Therefore while it's syntactically possible to pass an Activity
to initializer as a receiver and refer it as this
inside as @voddan suggests in this answer, the Lazy
itself is not capable of storing different value for different receivers.
An ability to have an external storage for extension properties may likely be covered by "Attached properties" feature KT-7210.
I don't think Lazy
should have this ability as it complicates significantly its implementation.