dasz
08/19/2019, 12:52 PMinterface A; class AI: A; interface B (val a: A); class BI (override val a: AI): B
conversion from A -> to AI where AI derives from APavlo Liapota
08/19/2019, 12:59 PMdasz
08/19/2019, 1:01 PMdasz
08/19/2019, 1:04 PMerror: type of 'x' doesn't match the type of the overridden var-property 'public abstract var x: Line_0.FooBase defined in Line_0.BarBase'
override var x: FooChild
Kotlin version 1.3.21 (JRE 1.8.0_152-release-1343-b01)dasz
08/19/2019, 1:05 PMdiesieben07
08/19/2019, 1:06 PMvar
it would violate the Liskov Substitution Principle:
The interface specifies that any interface instance can be assigned, but the implementation restricts that to only specific classes.diesieben07
08/19/2019, 1:07 PMdiesieben07
08/19/2019, 1:09 PMinterface A {
var foo: Any
}
class B : A(var foo: String)
val a: A = B("foo")
a.foo = 123 // compiles, because A.foo is any, but it's actually a B, which requires a String...
dasz
08/19/2019, 1:16 PMdiesieben07
08/19/2019, 1:18 PMval
only allows getting values out of the class. If the interface specifies "you can get an Any
here" then "you can get a `String`" here satisfies thatdiesieben07
08/19/2019, 1:18 PMvar
however it breaks:
"You can put Any
in here" is not satisfied by "You can put String
in here"dasz
08/19/2019, 1:26 PM