Created
May 10, 2019 15:57
-
-
Save arkivanov/aeac58760e9bf1b4357905f319bdaced to your computer and use it in GitHub Desktop.
Java invariance in Kotlin 4
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
fun bar(consumer: Consumer<in String>) { | |
if (consumer is Subject) { | |
val value: String = consumer.value // Compilation error | |
} | |
} | |
fun foo(consumer: Consumer<CharSequence>) { | |
bar(consumer) | |
} | |
interface Subject<T> : Consumer<T> { | |
val value: T | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment