Hi everyone. I'm trying to understand why the limi...
# announcements
d
Hi everyone. I'm trying to understand why the limitation of in-projections is not the same as the limitation of star-projections. Consider the following:
Copy code
class Crate<T : Animal>(var occupant: T)

fun Dog.withStarProjection(crate: Crate<*>) {
    // Compiles just fine
    val occupant: Animal = crate.occupant
}

fun Dog.withInProjection(crate: Crate<in Dog>) {
    // Type Mismatch - Required: Animal, Found: Any?
    val occupant: Animal = crate.occupant
}
Because of the type parameter constraint on
Crate
, I would expect
crate.occupant
to return an
Animal
in both cases, but with in-projections, it's returned as
Any?
instead. Any ideas why this is?