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.
Burt Beckwith
07/09/2019, 1:53 PMMarko 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...thana
07/09/2019, 1:55 PMval
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++
Marko Mitic
07/09/2019, 1:57 PMval isEmpty: Boolean
get() = this.size == 0
thana
07/09/2019, 1:58 PMNir
07/09/2019, 2:33 PMNir
07/09/2019, 2:34 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 PMNir
07/09/2019, 3:24 PMNir
07/09/2019, 3:25 PMNir
07/09/2019, 3:25 PMgildor
07/09/2019, 3:30 PMNir
07/09/2019, 3:34 PMNir
07/09/2019, 3:35 PMNir
07/09/2019, 3:35 PMopen class Foo {
open val x: Int get() { ... }
}
class Bar1 : Foo() {
override val x: Int = ...
}
Nir
07/09/2019, 3:35 PMNir
07/09/2019, 3:36 PMNir
07/09/2019, 3:36 PMgildor
07/09/2019, 4:05 PM