MENU

Fun & Interesting

Variance Positions in Scala, Demystified | Rock the JVM

Rock the JVM 8,113 lượt xem 4 years ago
Video Not Working? Fix It Now

Written version: https://blog.rockthejvm.com/scala-types-kinds/

Links from the video:
Why is contravariance so hard https://www.youtube.com/watch?v=b1ftkK1zhxI

The advanced Scala course that discusses lots of these type system issues including variance: https://rockthejvm.com/p/advanced-scala

This video is for the mature Scala developer. We talk about variance in Scala as an innocent question: if A extends B, should Thing[A] be a subtype of Thing[B]?

We then show the variance possibilities in Scala, and we explore the kind of problems this can pose. The infamous and cryptic "covariant type T occurs in contravariant position" will come up and we'll prove why that is the case.

Finally, we'll solve the "covariant type in contravariant position" problem with some generic type magic.

Follow Rock the JVM on:
LinkedIn: https://linkedin.com/company/rockthejvm
Twitter: https://twitter.com/rockthejvm
Blog: https://rockthejvm.com/blog

-------------------------------------------------------------------------
Home: https://rockthejvm.com
-------------------------------------------------------------------------

Comment