Skip to content

Instantly share code, notes, and snippets.

@arkivanov
Created May 10, 2019 15:57
Show Gist options
  • Save arkivanov/aeac58760e9bf1b4357905f319bdaced to your computer and use it in GitHub Desktop.
Save arkivanov/aeac58760e9bf1b4357905f319bdaced to your computer and use it in GitHub Desktop.
Java invariance in Kotlin 4
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