Skip to content
0:00 / 0:00

#variance#covariance#contravariance

Variance Positions in Scala, Demystified | Rock the JVM

Rock the JVM

27K subscribers • 59 videos on Hallway

YouTube
  • Recommended by 1 person: 1 in engineering communities.

Advanced. Deep dive for people who know the field.

9.1K views5 years ago1 recommendation

Programming languagesScalaDesign patterns

An in-depth look at covariance and contravariance in Scala, explaining why certain compiler errors occur and how to solve them.

Written version: blog.rockthejvm.com/scala-types-kinds/ Links from the video: Why is contravariance so hard youtube.com/watch?v=b1ftkK1zhxI The advanced Scala course that discusses lots of these type system issues including variance: 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: linkedin.com/company/rockthejvm Twitter: twitter.com/rockthejvm Blog: rockthejvm.com/blog ------------------------------------------------------------------------- Home: rockthejvm.com -------------------------------------------------------------------------

Why it's here

1 person recommends this

What people say. Recommended as an excellent deep dive into the mechanics of covariance and contravariance in Scala.

u/danielciocirlanin r/scala • Recommends

Demystifying Variance Positions in Scala