https://kotlinlang.org logo
Title
j

Johan Alkstål

09/11/2019, 7:43 PM
If I have classes that implement interface
Foo
, when making a
List<Foo>
should be possible without casting the classes to their interface type? When I do
fun listOfFoos(): List<Foo> {
    return listOf(
        FooA(),
        FooB(),
        FooC()
    )
}
it complains that each class is not a
Foo
but a
FooA
FooB
and
FooC
. I would have thought that since they all implement the interface
Foo
it would just work?
r

Ruckus

09/11/2019, 7:49 PM
It works fine for me: https://pl.kotl.in/g0AugAM0G
j

Johan Alkstål

09/11/2019, 8:37 PM
Doesn't compile for me. 😕 Type mismatch: inferred type is FooA but expected Foo
Okay now it suddenly did.