Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-----FRUIT BASKET--------
-----MANGO BASKET-------- PUT ANY MEMBER TO FRUIT BASKET AS MANGO - OK, GET ANY MEMBER FROM FRUIT AS MANGO - NOT OK
-----MANGO BASKET-------- PUT ANY MEMBER TO KESHAR-MANGO BASKET AS MANGO - NOT OK, GET ANY MEMBER FROM KESHAR-MANGO AS MANGO - OK
-----KESHAR-MANGO BASKET--------
interface Animal{
fun mateWith(dog: Dog)
fun makeBaby():Dog
}
object Dog: Animal {
//Doesnt support expanding input type possibilities, contraavarience
override fun mateWith(otherAnimal: Animal) {
}
//Does support reducing output type possibilities, covarience
override fun makeBaby(): Animal {
return object :Animal{
override fun mateWith(dog: Dog) {
}
override fun makeBaby(): Dog {
return Dog
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment