https://kotlinlang.org logo
Title
l

leosan

04/24/2018, 4:36 PM
is there a way to create a
Delegates.observable
of a read-only property? e.g.
data class Foo(bar:Boolean, car:Boolean)
val foo by Delegates.observable(Foo(false,false)){...}
foo.bar = true
g

gildor

04/24/2018, 4:45 PM
Observable field cannot detect such changes and notify.
foo.bar = true
To do that bar must be Delegates.observable itself
l

leosan

04/24/2018, 4:50 PM
hmm 😕 ty, I just found out from the docs
d

dave08

04/24/2018, 7:40 PM
Maybe you could make the setter private though?
g

gildor

04/25/2018, 5:22 AM
make the setter private though
But sample code itself is impossible, you cannot observe changes of nested property (foo.bar), you can observe changes of foo itself