felislynx
04/18/2018, 12:58 PMopen class Foo {
}
class Bar:Foo(){
}
open class FooList {
open var list:List<Foo>?=null
}
class BarList:FooList(){
override var list:List<Bar>?=null
}
open class BaseTest {
open var llist:List<FooList>?=null
}
class BaseTestTwo : BaseTest {
override var llist:List<BarList>?=null
}
Andreas Sinz
04/18/2018, 1:00 PMBaseTestTwo
failing?felislynx
04/18/2018, 1:01 PMopen class FooList<T:Foo> {
open var list: List<T>? = null
}
class BarList : FooList<Bar>() {
override var list: List<Bar>? = null
}
Andreas Sinz
04/18/2018, 1:05 PMlist: List<T>?
is a var
and thus is reassignablefelislynx
04/18/2018, 1:07 PMAndreas Sinz
04/18/2018, 1:09 PMFooList<T: Foo>
is invariant, that means FooList<Bar>
is not a subtype of FooList<Foo>
felislynx
04/18/2018, 1:10 PMAndreas Sinz
04/18/2018, 1:10 PMval
and use FooList<out T: Foo>
felislynx
04/18/2018, 1:13 PMAndreas Sinz
04/18/2018, 1:16 PMfelislynx
04/18/2018, 1:18 PMAndreas Sinz
04/18/2018, 1:20 PMfelislynx
04/18/2018, 1:21 PM