How do property delegation work? Extension propert...
# announcements
s
How do property delegation work? Extension properties can't have a value. but I can delegate them with lazy? Where is the lazy value stored?
d
An extension property delegate's getter delegates calls to a global delegate object. In the case of lazy, there can be no references to the receiver. The getValue operator does get a reference to the receiver in the first parameter. It could conceivably use some kind of map to store an attribute separately for each instance. Delegates allow you to encapsulate this kind of logic.
k
So in other words,
val Foo.x by lazy { ... }
means there is only a singe
Lazy
instance that is "shared" by all
Foo
instances, so there's no real point if even making it an extension property.
💯 2