https://kotlinlang.org logo
Title
c

chriswayoub

04/20/2017, 4:40 AM
Is there an alternative to delegated properties for observing changes to all properties on a class? Even a hacky reflection-driven way would be fine... Right now, I'm having to add the delegate to every single property and it's easy to miss one (especially in subclasses)
l

louiscad

04/21/2017, 11:32 AM
You can write a custom generic delegate (plus for primitive types if you have to avoid autoboxing overhead) that takes as a parameter something that will notify observers, and use this delegate for all of your properties. Unfortunately, there's no way to enforce it on subclasses other than documentation
c

chriswayoub

04/22/2017, 3:13 AM
Thanks for the suggestion. I ended up going in a similar direction, and although it’s not ideal to be able to accidentally forget to add the delegate to a property, it’s working pretty well.
👍 1