Тёмный

Variance... without Generics! 

Dave Leeds
Подписаться 4,3 тыс.
Просмотров 4,9 тыс.
50% 1

Did you know that you can use covariance and contravariance in Kotlin without generics? Unlock the mental model of generic variance by first understanding how variance works with regular type hierarchies!
✨ New to Kotlin? Start here: typealias.com/start/
... or pick up the new Leanpub Edition! book.typealias.com/
🚀 I just launched a new email newsletter!
Sign up here: newsletter.typealias.com/
00:00 Introduction
00:35 Upholding the Contract in Subtypes
02:05 Covariance
04:12 Contravariance
06:54 Summary of Variance
07:15 Why Generic Variance Works
08:10 Wrap-up
#kotlin #androiddevelopment

Наука

Опубликовано:

 

15 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 49   
@typealias
@typealias 3 месяца назад
Big thanks to the folks who joined the premiere and said hello in chat! Maybe we can do that again next time. I'm also considering whether an occasional livestream would be helpful, where I might be able to respond to chat questions and comments in video instead of text. Anyway, if you've got thoughts about any of that, let me know!
@Mike-er2ih
@Mike-er2ih 3 месяца назад
I do not know how you do it Dave but you explain everything so clear. I guess its what they call a teaching talent!
@typealias
@typealias 3 месяца назад
Haha, thanks so much, Mike! I do enjoy the challenge!
@JentaroYusong
@JentaroYusong 3 месяца назад
I loved this episode! Always had trouble with the nomenclature. Using a non-generic example is really helpful, thank you!
@typealias
@typealias 3 месяца назад
Thanks so much, Jentaro! Yes, some of the concepts seem a bit counterintuitive at first, but I'm glad this was helpful!
@randoman1212
@randoman1212 3 месяца назад
Best explanation on this topic I've seen. Great work!
@typealias
@typealias 2 месяца назад
Hey, wow! Thank you so much!
3 месяца назад
Thanks youtube for recommend this channel. It definitely deserve more views! You teach as clear as day, even though I'm not a native english speaker. Thanks for sharing your knowledge.
@typealias
@typealias 3 месяца назад
Thank you so much! I'm especially happy to hear that it's helpful for someone who doesn't natively speak English!
@user-ig1ty7dl1k
@user-ig1ty7dl1k Месяц назад
This is the best explanation I ever heard! Please dont stop doing your lessons. Also want to say thank you for your book, this is really perfect!
@typealias
@typealias Месяц назад
Thank you so much! I'm so glad to hear that you've enjoyed the videos and book! I'll keep at it! 👍
@gekylafas
@gekylafas 3 месяца назад
One of the best explanations of variance I have seen/read! Thanks!
@typealias
@typealias 3 месяца назад
You're most welcome! I'm glad you liked it!
@olivierm6425
@olivierm6425 3 месяца назад
Your online book and videos are great and useful. Cannot recommend enough. Thank you sir!
@typealias
@typealias 3 месяца назад
Thank you so much - I'm so glad you've found them useful!
@husammuala
@husammuala 3 месяца назад
Thank you so much! Clean explanation and straight to the point. Please continue uploading videos
@typealias
@typealias 3 месяца назад
Thanks so much! I'll keep at it!
@AntonioLeivaCom
@AntonioLeivaCom 3 месяца назад
I love your videos! I’m always struggling to understand and retain in my brain these to concepts, and this one will help a lot!
@typealias
@typealias 3 месяца назад
Antonio! Thanks so much! Yes, variance can certainly seem counterintuitive, so I've often had to think twice about it, too. Glad you enjoyed the video!
@robkeazor9709
@robkeazor9709 3 месяца назад
Bro , the way you explained thus was flawless. Thanks
@typealias
@typealias 3 месяца назад
Haha, thank you! I'm glad you liked it!
@L4szcZ
@L4szcZ 3 месяца назад
amazing work, you don't even know how much I apprecaite your content!
@typealias
@typealias 3 месяца назад
Thank you so much! I'm so glad to hear you've enjoyed it!
@sevbanthebuyer
@sevbanthebuyer 3 месяца назад
Great ! Very comprehensive, thank you for your effort.
@typealias
@typealias 3 месяца назад
You're most welcome!
@Alchemist10241
@Alchemist10241 3 месяца назад
I never completely know in and out keywords, Now I totally get it, well don
@typealias
@typealias 3 месяца назад
Thank you so much! I'm glad you found it helpful!
@khouari1
@khouari1 2 месяца назад
Very nice, high quality, video! Thanks!
@typealias
@typealias 2 месяца назад
You're most welcome! I'm glad you liked it!
@avalagum7957
@avalagum7957 3 месяца назад
OMG! Today I understand a bit about covariance and contravariance. Thank you so much.
@typealias
@typealias 3 месяца назад
I'm so glad it was helpful! And you're most welcome!
@darwincordova8241
@darwincordova8241 2 месяца назад
Man, your explanation is great!
@typealias
@typealias 2 месяца назад
Thanks so much, Darwin! I'm glad you liked it!
@vasilemoraru89
@vasilemoraru89 2 месяца назад
Very well explained !!!
@funkypopper
@funkypopper 3 месяца назад
Thank you for your video. I had misunderstood before watching your video that variance was only relevant to generics, but that was incorrect.
@typealias
@typealias 3 месяца назад
You're most welcome! I'm glad you found it helpful!
@ruivo_dev
@ruivo_dev 3 месяца назад
Great content, thanks!
@typealias
@typealias 3 месяца назад
You're most welcome! I'm glad you liked it!
@shriharshabhagwat6289
@shriharshabhagwat6289 18 дней назад
Talent in Teaching ✅
@lp1926.guitars
@lp1926.guitars 2 месяца назад
You're very good at this 👏
@typealias
@typealias 2 месяца назад
Hey, thank you so much!
@MikeMcCartney
@MikeMcCartney 3 месяца назад
Great video, but I'd like to know a bit more about why params should be contravariant and why that isn't considered 'breaking the contract'.
@typealias
@typealias 3 месяца назад
Hey Mike, sure thing! Let's say you've got a birthday card that you want to send to your friend. You need to find an envelope receptacle to mail it (i.e., a collection box that accepts envelopes). In this case, the contract you need is that _the receptacle must accept an envelope_. A thin mail slot at an apartment complex would meet your needs - it fulfills the contract, because it accepts an envelope. Now, if you were to go to the post office, they might have a receptacle that's big enough to receive either an envelope _or_ a box package - any kind of mail. That receptacle would _also_ meet your needs, because it still accepts an envelope. Sure, it also happens to accept packages, but that fact is irrelevant to your situation - as long as it accepts an envelope, it meets the contract. Similarly, in Kotlin, you could assign the post office mail receptacle to a variable that's declared as an envelope receptacle, because it can still accept envelopes. --- interface Mail interface Envelope : Mail interface Package : Mail val mailSlot: (Envelope) -> Unit = { /* ... */ } val postOffice: (Mail) -> Unit = { /* ... */ } var envelopeReceptacle: (Envelope) -> Unit envelopeReceptacle = mailSlot // OK - accepts envelopes envelopeReceptacle = postOffice // OK - also still accepts envelopes --- Does that example help to clarify it better?
@MikeMcCartney
@MikeMcCartney 3 месяца назад
Thanks @@typealias , I understand the examples but it's also easy to think up examples where this doesn't make sense. You could change the parameter type in the implementation to "Any". Very useful video though - many thanks!
@typealias
@typealias 3 месяца назад
Okay, thanks Mike! If you want, feel free to direct-message me on X or LinkedIn, and I can send you early access to Chapter 19, and see if you still have unanswered questions after reading it. (I'm sure if you'd have some questions, other people would, too!)
@srikrishnanunna1
@srikrishnanunna1 3 месяца назад
Now I am more confused, but some level of knowledge is acquired. Maybe we need some kind of mnemonics with images to understand it more.
@srikrishnanunna1
@srikrishnanunna1 3 месяца назад
I will try to watch the entire video 3-4 times and write notes on it to better understand it.
@typealias
@typealias 3 месяца назад
Wow, watching the video multiple times and taking notes - that's dedication! 👏 The concepts in this video might make more sense for you when chapter 19 comes out, so if it's still not connecting for you after a few times through, don't worry too much!
@srikrishnanunna1
@srikrishnanunna1 2 месяца назад
@@typealias Took 4 more times to rewatch the entire video and understood a lot! Understanding Variance without generics did help to understand how Variance with Generics works! Very nicely explained! Thanks.
Далее
5 Fun Ways to Use Extension Functions in Kotlin
18:46
Аварийный выход
00:38
Просмотров 666 тыс.
heavy boot #tiktok
00:16
Просмотров 822 тыс.
UML class diagrams
12:24
Просмотров 355 тыс.
Reified Type Parameters
10:15
Просмотров 1,7 тыс.
Covariance and Contravariance
13:31
Просмотров 11 тыс.
Intersection Types in Kotlin
8:45
Просмотров 3,3 тыс.
Three Simple Rules for Subtypes
13:52
Просмотров 1,8 тыс.
Every Kind of Class in Kotlin
10:44
Просмотров 6 тыс.
Inline Functions: inline, crossinline, and noinline
11:59
Generics in Kotlin: Covariance and Contravariance
8:27
wireless switch without wires part 6
0:49
Просмотров 3,8 млн
WWDC 2024 - June 10 | Apple
1:43:37
Просмотров 10 млн