Last active
December 12, 2017 09:48
-
-
Save kingori/73b1776c44ad2a5296746134a2cc40c2 to your computer and use it in GitHub Desktop.
var/val override test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface A { | |
val myVal: Boolean | |
var myVar: Boolean | |
} | |
//no problem | |
class B : A { | |
override val myVal = false | |
override var myVar = false | |
} | |
class C : A { | |
override val myVal: Boolean | |
get() = false | |
override var myVar: Boolean //no compile error | |
get() = false | |
set(value) {} //warning:redundant setter | |
} | |
class D : A { | |
override val myVal: Boolean | |
get() = false | |
override var myVar: Boolean //compile error : property must be initalized | |
get() = false | |
set(value) { field= value} //warning:redundant setter | |
} | |
class E : A { | |
override val myVal: Boolean | |
get() = false | |
override var myVar: Boolean = false | |
get() = false | |
set(value) { field = value} //warning:redundant setter | |
} | |
class F : A { | |
override val myVal: Boolean | |
get() = false | |
override var myVar: Boolean = false | |
get() = false | |
set(value) { field= field} //no warning: ignore new value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment