# Covariance and contravariance: Is something possible in Kotlin that is impossible in Java?

**URL:** <https://discuss.kotlinlang.org/t/covariance-and-contravariance-is-something-possible-in-kotlin-that-is-impossible-in-java/28560>\
**Category:** Uncategorized\
**Created:** [May 1, 2024, 3:51pm UTC](https://discuss.kotlinlang.org/t/covariance-and-contravariance-is-something-possible-in-kotlin-that-is-impossible-in-java/28560 "2024-05-01T15:51:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![medium](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/medium/32/10404_2.png) [@medium](https://discuss.kotlinlang.org/u/medium)\
**Post date:** [May 1, 2024, 3:51pm UTC](https://discuss.kotlinlang.org/t/covariance-and-contravariance-is-something-possible-in-kotlin-that-is-impossible-in-java/28560/1 "2024-05-01T15:51:34Z")

</div>

I’ve read the [documentation about variance](https://kotlinlang.org/docs/generics.html) and tried to come up with an example that is impossible in Java but possible in Kotlin. But in the end I was possible to solve all my Java examples with `? extends Something` or `? super Something`.

Is there something that is possible with Kotlins approach to variance only but not with Javas?

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [May 1, 2024, 7:41pm UTC](https://discuss.kotlinlang.org/t/covariance-and-contravariance-is-something-possible-in-kotlin-that-is-impossible-in-java/28560/2 "2024-05-01T19:41:33Z")

</div>

Why do you need this? Generics generally don’t provide anything that is not possible without them. Also, both implementations provide similar functionality. One notable difference is that Kotlin supports declaration-site variance and Java does not. Additionally, I believe Kotlin generics are stricter in some cases, but right now I don’t remember what was the case exactly.

---

<div class="post-metadata">

**Author:** ![medium](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/medium/32/10404_2.png) [@medium](https://discuss.kotlinlang.org/u/medium)\
**Post date:** [May 2, 2024, 3:40pm UTC](https://discuss.kotlinlang.org/t/covariance-and-contravariance-is-something-possible-in-kotlin-that-is-impossible-in-java/28560/3 "2024-05-02T15:40:38Z")

</div>

I’m interested in the differences out of curiosity. I have an example in my mind (which I can no longer find), where something should have been possible with Kotlin generics that would be impossible with Java. But after looking around for a while I haven’t found an actual example.
