thana
07/09/2019, 1:51 PMval
from an interface be overwritten as var
in the implementation?Burt Beckwith
07/09/2019, 1:53 PMYou can also override a val property with a var property, but not vice versa. This is allowed because a val property essentially declares a getter method, and overriding it as a var additionally declares a setter method in the derived class.
Marko Mitic
07/09/2019, 1:54 PMval
thana
07/09/2019, 1:55 PMset
of the val
is private and declaring it var
in the implementation grants access that shouldn't be allowed...val
and then it changes...Alowaniak
07/09/2019, 1:55 PMthana
07/09/2019, 1:56 PMMarko Mitic
07/09/2019, 1:56 PMval
properties are read-only, not immutablethana
07/09/2019, 1:56 PMMarko Mitic
07/09/2019, 1:57 PMval counter: Int
get() = _counter++
val isEmpty: Boolean
get() = this.size == 0
thana
07/09/2019, 1:58 PMNir
07/09/2019, 2:33 PMgildor
07/09/2019, 3:06 PMderived class cannot add a settersame in Kotlin, you just override gettere and setters, underlying backing field is just implementation detail
Nir
07/09/2019, 3:24 PMgildor
07/09/2019, 3:30 PMNir
07/09/2019, 3:34 PMopen class Foo {
open val x: Int get() { ... }
}
class Bar1 : Foo() {
override val x: Int = ...
}
gildor
07/09/2019, 4:05 PM