What is property delegation in Kotlin?
How can you write your own custom delegates?
Examples of how we used delegation at sporttotal.tv and how it made Android databinding much simpler for us
can be implemented: operator fun provideDelegate( thisRef: Any?, property: KProperty<*> ): ReadOnlyProperty<MyUI, T> { … } One of the possible use cases of provideDelegate is to check property consistency when the property is created, not only in its getter or setter.
( property: KProperty<*>, oldValue: T, newValue: T ) -> Unit ): ReadWriteProperty<Any?, T> var max: Int by observable(0) { property, oldValue, newValue -> … }
set(value) { field = value notifyPropertyChanged(BR. title) } @Bindable var showLoader: Boolean = false set(value) { field = value notifyPropertyChanged(BR. showLoader) } @Bindable var error: String? = null set(value) { field = value notifyPropertyChanged(BR. error) }