Skip to content

Instantly share code, notes, and snippets.

@kingori
Last active December 12, 2017 09:48
Show Gist options
  • Save kingori/73b1776c44ad2a5296746134a2cc40c2 to your computer and use it in GitHub Desktop.
Save kingori/73b1776c44ad2a5296746134a2cc40c2 to your computer and use it in GitHub Desktop.
var/val override test
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