Is there way to add extensions to variables via de...
# announcements
a
Is there way to add extensions to variables via delegation so that they may be reusable. Possible use case is to add a listener for the change in property, i know this can be done using external variable list containing lambdas and observable delegation but it is not reusable, as we need to create list for every variable we want to became observable, and it also doesn't reads/looks so good because you register observer lambda using member function of class not by the variable itself.
m
a
Not exactly, i want to know that just like extension function is there a way to add some functions to specified properties.
(not a specific class)
m
You can only add extensions to types, not to variables or functions. You can only mess around with class properties using property delegation.
As long as the property is delegated you could write something like this:
observe(someObject::someVariable) { … }
a
observe is not defined anywhere @Marc Knaup
m
Yeah you have to write it
And the delegate
a
ohh ok
m
Depends on what you want to achieve
Could also look like this:
someObject::someProperty.observe { … }
You’d have to write
.observe()
and
someProperty
must use a delegate you’ve written.
Maybe you can even put
someObject::someProperty
in a
Map
for later references, but you won’t get change notifications without a delegate
a
where do i write .observe(block: ()->Unit)?
to a variable
m
It’s probably not a clean approach anyway and something like
val someProperty: Observable<Int>
should be used.
a
Even if its doesn't look so great but Its ok. A quick question What is use of
isAccessible = true
?