lazy calls the initializer function the first time it is accessed, and then saves the value returned by initializer to return this value on sequential access.
A lazy instance is capable of storing exactly one value. When you delegate the extension property to the lazy instance, you get a single lazy instance serving getValue requests from all instances of the receiver type, in your case it is Activity . This results in calculating the lazy value only for the first Activity and using this value for all subsequent calls for other Activity instances.
Therefore, although you can syntactically pass Activity to the initializer as a receiver and call it this inside, since @voddan offers this answer , lazy itself is not able to store a different value for different receivers.
The ability to have external storage for extension properties can probably be covered by the Attached Properties function of KT-7210 . I do not think lazy should have this ability, as this greatly complicates its implementation.
source share