Is there a way to specify that a container that im...
# getting-started
c
Is there a way to specify that a container that implements
List
has a subtype that contains elements that are a subtype of the elements of the parent?
Copy code
interface A
class AImpl : A

interface Container : List<A>
class ContainerImpl : Container, List<AImpl> {
    // …
}
I'm getting:
Copy code
Type parameter 'E' of 'interface List<out E> : Collection<E>' has inconsistent values: A, AImpl.
I know I can do:
Copy code
interface Container<T> : List<T>
class ContainerImpl : Container<AImpl> {
    // …
}
but it doesn't make sense for
Container
to be parameterized in my case.
🚫 1
e
y
This is the closest you can get probably:
Copy code
interface A
class AImpl : A

typealias Container = ContainerT<*>
interface ContainerT<out T: A> : List<T>
class ContainerImpl : ContainerT<AImpl>
c
Yeah that's what I'm thinking of. But since it's a core type of the library, it's going to be confusing to users still.