Backing Field in Kotlin

This post was originally posted at https://agrawalsuneet.github.io/blogs/backing-field-in-kotlin/
var selectedColor: Int = someDefaultValue
get() = selectedColor
set(value) {
this.selectedColor = value
doSomething()
}
var selectedColor: Int = someDefaultValue
get() = field
set(value) {
field = value
}

Please continue reading at https://agrawalsuneet.github.io/blogs/backing-field-in-kotlin/

--

--

--

https://agrawalsuneet.github.io/

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Suneet Agrawal

Suneet Agrawal

https://agrawalsuneet.github.io/

More from Medium

How to Use Generics in Kotlin

3 Best Practices for Using Named Arguments in Kotlin

Kotlin Functions

Kotlin Programming Language: Everything You Need to Know