Contravariance in Scala: Why Is It So Hard? | Rock the JVM

preview_player
Показать описание

This video is for the Scala programmer who's only been using generics in their basic form: either with collections, or simply attaching a type argument to a class/trait and minding their own business.

I will introduce the concepts of co- and contravariance and why they are useful, with a few examples and some rules of thumb to follow, without getting into the academic weeds that otherwise make these concepts seem so obscure and confusing to most programmers.

Follow Rock the JVM on:

-------------------------------------------------------------------------
-------------------------------------------------------------------------
Рекомендации по теме
Комментарии
Автор

To remember this Java developers used "PECS" mnemonics (Producer - extends, Consumer - super). Kotlin uses in/out keywords (in - for being able to put/pass an object into container, out - to get from the container). Scala has the most concise syntax for that. Thanks for the lesson!

kirillgavrilov
Автор

You definitely have a talent for explanation

nao_concordo
Автор

Taking my fedora off to honor the humanity-changing great feat of Laika the space dog 😔🎩
You will forever be in our hearts, comrade Laika ❤
Let's honor her memory by studying hard, so that the people of the world can finally tame the boundless nature of outer space... With the help of Scala, obviously.

awesomebearaudiobooks
Автор

I have read several explanations about the variances subject and never felt like I fully understood it.
This video is the best explanation I found, now I feel very comfortable with it.
Thanks a lot and please make more videos like this :-)

yohaitol
Автор

The best explanation of contravariance I’ve seen.

_mumbler_
Автор

Finally, someone could make me understand this thing... BTW I came here without any knowledge of Scala (my background is from Kotlin lol). The way that you explained it is so good that I could understand it even with examples in a language that I had never seeing before. Thank you so much.

hinocenciopaulo
Автор

Slowly coming to terms with this concept but the consumes vs. produces rule of thumb is the best summary I've seen so far of when to apply variance. 👍

jimaaman
Автор

This is the best explanation of this concept I have seen till now! Thanks, Daniel!

Автор

wow, underrated channel, i remember drawing a lot of diagrams explaining contravariance in stackoverflow once so i thought i understood it but you have an incredibly effective way of distilling information. i'm going to watch all your videos just to see how you explain it ==)

vetiarvind
Автор

Best Scala tutorials evere, I'm so happy I found your channe. Perfect 💯

sergeykvartalnov
Автор

Really really good explanation. It feels quite intuitive now

mikepictor
Автор

What a wonderful video, this subject was so vague for me, thank you !

UniformDelta
Автор

Awesome video man, quite simple, after some research I was almost at the starting point to understand this, your approach rocks, just one complaint, Hachi was not a lucky dog, he is a legend, 👏

OmarMendozaKS
Автор

I've benn waiting for this video!

flaviodasilveirapepino
Автор

The best co- vs contravariance explanation in the world

temoncher
Автор

An interesting natural example where variance and contravariance exist, even if doesn't seem logical: human blood types.
In terms of blood cell compatibility, O is the universal donor (provides for every other), while AB is the universal receiver.
In terms of plasma is the other way around: AB is the universal donor, while O is the universal receiver

Alchimystic
Автор

As always very well explained.
Thank you.

viddyasagarverma
Автор

so awesomely explained I finally got it. Thank you!

TJ-hsqm
Автор

Thanks a lot :). I learnt something completely new today

rheafernandeshallu
Автор

I read effective java to thousand articles .Contra-variance remained a puzzle.I think today it sinked in.Thanks.

mompyish
welcome to shbcf.ru