Created
June 20, 2020 18:48
-
-
Save magdamiu/08842e3d8dfcff4691fc87a6df220f51 to your computer and use it in GitHub Desktop.
Covariance in Kotlin
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
class CovarianceSample<T> | |
fun main() { | |
val firstSample: CovarianceSample<Any> = CovarianceSample<Int>() // Error: Type mismatch | |
val secondSample: CovarianceSample<out Any> = CovarianceSample<String>() // OK , String is a subtype of Any | |
val thirdSample: CovarianceSample<out String> = CovarianceSample<Any>() // Error: Type mismatch | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment