Created
August 28, 2019 03:02
-
-
Save 1nsp1r3rnzt/36bc7c98139af090df7bdc9201f74ef2 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
open class FLower(){ | |
} | |
class Rose: FLower(){} | |
//A garden has flowers. | |
open class Garden<out T: FLower>(){ | |
val flowers: List<T> = listOf() | |
fun pickFlower(i: Int ):T = flowers[i] | |
fun plantFLower(flower: T) {} | |
} | |
fun waterGarden( garden: Garden<FLower>) {} | |
// when we talk about in and out position of covariance , we talk about memmber functions and not top level functions. | |
fun tendGarden(roseGarden: Garden<Rose>) { | |
waterGarden(roseGarden) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment