When overriding a `val` property in a subclass, on...
# announcements
j
When overriding a
val
property in a subclass, one can specify a subtype of the original type as return type.
Copy code
open class A() {
    open val property: A? get() = A() 
…
Class B : A() {
    override val property: B? get() = B()
On a
var
, specifying the setters type to something below the original is obviously not possible. But I would expect that I could do that for the getter, like so
Copy code
Class B : A() {
    override var property: A? 
        get(): B? = B()
That fails however with
Getter return type must be equal to the type of the property.
Is there any way of achieving this? Does it make sense to file a feature request for allowing subtypes as return type of getters?