If I have classes that implement interface `Foo`, ...
# getting-started
j
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
Copy code
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
It works fine for me: https://pl.kotl.in/g0AugAM0G
j
Doesn't compile for me. 😕 Type mismatch: inferred type is FooA but expected Foo
Okay now it suddenly did.