Dave Leeds
01/28/2018, 10:46 PMclass 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?