Last active
August 26, 2022 21:20
-
-
Save omkar-tenkale/99a6812408703953801cd2018694bb8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----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