Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Contravariance in Kotlin
open class Vehicle
class Bicycle : Vehicle()
class Container<in T>
fun main() {
var containerBicycle: Container<Bicycle> = Container<Vehicle>() // OK
var containerVehicle: Container<Vehicle> = Container<Bicycle>() // Error: Type mismatch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.