Is there some workaround for this? When `a` is a v...
# getting-started
z
Is there some workaround for this? When
a
is a var I get this error:
Copy code
Type of 'a' doesn't match the type of the overridden 'var' property 'var a: Letter' defined in '/Base'
It doesn't occur when it's a val
Copy code
open class Base {
    open var a: Letter = Letter()
}

class BaseExt : Base() {
    override var a: A = A()
}

open class Letter

class A : Letter()
j
A
is a subtype of
Letter
, so if it's a
val
all is good. The problem when it's a
var
is that someone could assign any subtype of
Letter
to
a
, which would break instances of `BaseExt`:
Copy code
val ext: Base = BaseExt()
ext.a = Letter() // respects the interface of Base, yet shouldn't be allowed for BaseExt
plus1 1