Skip to content

Instantly share code, notes, and snippets.

@1nsp1r3rnzt
Created August 28, 2019 03:02
Show Gist options
  • Save 1nsp1r3rnzt/36bc7c98139af090df7bdc9201f74ef2 to your computer and use it in GitHub Desktop.
Save 1nsp1r3rnzt/36bc7c98139af090df7bdc9201f74ef2 to your computer and use it in GitHub Desktop.
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