Overriding setter property in extending class


#1

Is there any way to override a setter property in extending class?

class A {

var selectedColor: Int
        get() = selectedColor
        set(selectedColor) {
            this.selectedColor = selectedColor
            doSomething()
        }
}

Class B : A {
  override var selectedColor: Int
        get() = selectedColor
        set(selectedColor) {
            this.selectedColor = selectedColor
            doSomethingElse()
        }
}

the keyword override is showing error saying
’selectedColor’ is final and cannot be overridden
Is there something I am missing?


#2

In Kotlin alles is final by default, to make it overridable, you need to add open.
for more info see:

https://kotlinlang.org/docs/reference/classes.html#overriding-properties