Тёмный

Generics in Kotlin: Covariance and Contravariance 

K T
Подписаться 516
Просмотров 18 тыс.
50% 1

This week, Amanda covers types, classes, and generics in Kotlin.
Blog here: / introduction-to-kotlin...
Github repo here: github.com/Kot...
Are you interested in contributing? Contact us or head over to Github to get started!
Github: github.com/Kot...
Email: kthursdays@gmail.com

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

 

26 сен 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 32   
@mihaifumarel3349
@mihaifumarel3349 4 года назад
One thing I don't get is why we would need different keywords for the covariance/ contravariance. Both are essentially saying "use a type that is a subtype of the provided value". Why do I care if the value is consumed or produced? The covariance part is very clear, but contravariance confuses me. It surely doesn't mean "any class that is a super class of the provided argument", is it? Because that doesn't make much sense to me. Questions aside, the content was very good and you're fun to listen to. Keep up the good work!
@Rajmanov
@Rajmanov 2 года назад
same for me, the contravariance it's difficult to grasp because there is not any great example to recognize the pattern
@mkc0321
@mkc0321 3 года назад
after watching several times i only understood that when we use 'out T' then we can only use T as return type and when we use 'in T' the we can use T only for input parameter in a class
@EagleEye404
@EagleEye404 3 года назад
Confusing in and out. Yep my understanding is same as you.
@2NormalHuman
@2NormalHuman 2 года назад
yeah she didn't explain it detailed enough
@vakho30
@vakho30 2 года назад
What I've understood from the Kotlin in Action book is that when we use 'in' variant we can pass supertypes also and when we use 'out' variant we can pass subtypes.
@DonutAgain
@DonutAgain Год назад
You are correct. in means that a type parameter can only be used as an input, and out means that a type parameter can only be used as an output. List is defined like this: interface List : Collection { .... }, because we will make a new List, and that's an output. One can assign subtype instance to super type variable, the other once vice versa. We can memorize the relation using List, which is an example of out/covariance, and we can assign List/supperType with an instance of ArrayList()/subType; and for in/contravariance, it's the inverse; and without either in or out keyword, then it's called invariance, between the supertype and subtype there is no assignment allowed. For example, since List is using out/covariance, the first is correct, because Int is Number. But if List is in/contravariance, then the second will be correct; without in or out/invariance, then none of these is correct. (1) var numList: List = listOf() (2) var intList: List = listOf()
@andk6893
@andk6893 7 месяцев назад
@@vakho30thank you! :)
@NicksonKaigi
@NicksonKaigi 5 лет назад
This is both humorous and informative. Sloths and Pandas FTW !
@24035709
@24035709 4 года назад
Only if I can understand from 5:58
@pcfreak1992
@pcfreak1992 3 года назад
I don't know, I still don't understand what covariance or contravariance means and when to use which keyword.
@mhdunknown
@mhdunknown 2 года назад
Still don't get it lol, don't think it's an issue with the instructor though, she clearly knows what she's talking about, but the whole concept itself just isn't easy to grasp, maybe it'll get better as I use Kotlin more and more, and this video definitely helped in giving me an initial idea even though I still don't feel like I got it 100% so much appreciated!
@Onduty682
@Onduty682 9 месяцев назад
Not bad explanation, thank you
@jaymartinez311
@jaymartinez311 4 года назад
She said squaaaad 😆😂😆😂🤣
@skotch_izolentovich
@skotch_izolentovich 2 года назад
Amazing voice nice to listen. But I still don't understand what contravariance is.
@vikaspandey7053
@vikaspandey7053 5 лет назад
something valuable, helpful, useful
@theabrahamherrera
@theabrahamherrera 3 года назад
Keep making videos!
@wavecycle
@wavecycle 4 года назад
Good video, would help visibility if project panel wasn't taking up 1/3 of screen tho.
@asadullahilyas
@asadullahilyas 2 года назад
But you didn’t use the keyword out or in anywhere? What you did has nothing to do with covariance or contra-variance. You just referred the objects of subclasses with the reference of the super class.
@kyletycholiz8631
@kyletycholiz8631 5 лет назад
great explanation. got a bit complex at the end, so may require a few more views. thank you
@SimBol1216
@SimBol1216 3 года назад
Yo, that intro beat would make for a 🔥 hip hop track
@RakhiDhavale
@RakhiDhavale 5 лет назад
well explained :)
@davorstajcer2664
@davorstajcer2664 4 года назад
Can anyone please send me the name of the song if you know.
@vikaspandey7053
@vikaspandey7053 5 лет назад
whats the music in the end, and it is your phone ringtone too.
@syednoorullahshah9194
@syednoorullahshah9194 4 года назад
Was watching in full screen, i thought my laptop was about to shutdown due to low battery @1:46
@iftak01
@iftak01 3 года назад
Really great and helpful video..really needed topic, thanks! I Subbed, make more
@huttarl
@huttarl Год назад
For a video that's supposed to be about covariance and contravariance, this doesn't explain much. The examples are pleasant though.
@БейбутТукибаев-с2ь
this is really bad explanation , especially Contravariance part...
@yourpapa69
@yourpapa69 3 года назад
If I didn't know about covariance/contrvariance I wouldn't understand nothing of this explanation 😀 Ends like "Oh, I have an incomiming call, have nice day"
@johnnyshoesofthetwo7374
@johnnyshoesofthetwo7374 3 года назад
yeh, you think she would have, at least, removed it from the video.
@ahmadnurokhim593
@ahmadnurokhim593 4 года назад
Nice
Далее
Kotlin Newbie to Pro - GENERICS - Part 29
19:41
Просмотров 32 тыс.
Generics in Kotlin: Reified Generics in Kotlin
5:48
We finally APPROVED @ZachChoi
00:31
Просмотров 2,2 млн
Это ваши Патрики ?
00:33
Просмотров 28 тыс.
Generics in Kotlin: Higher-Order Functions
10:03
Просмотров 1 тыс.
10 Kotlin Tricks in 10 ish minutes by Jake Wharton
17:24
Gitlab DELETING Production Databases | Prime Reacts
17:27
5 Fatal Coroutine Mistakes Nobody Tells You About
18:15
Zig for Impatient Devs
9:48
Просмотров 90 тыс.
This Is Why Python Data Classes Are Awesome
22:19
Просмотров 807 тыс.
Kotlin In Out types in Generics in 20 minutes
20:12
Просмотров 6 тыс.
Premature Optimization
12:39
Просмотров 809 тыс.