Java super and extends tutorial (Java Generics Tutorial).

preview_player
Показать описание
In this tutorial, the issues around polymorphic declarations and type erasure in generic declarations are discussed. This leads on to a discussion of the super and extends keywords and how they solve these issues. Example code demonstrates their usage in action.

0:00 Introduction
0:21 Type Erasure
1:01 Polymorphism issue
4:33 extends - polymorphic declarations
6:00 super - polymorphic declarations
6:55 declarations for code examples
7:25 extends example
10:43 super example
Рекомендации по теме
Комментарии
Автор

Very well explained. I've struggled to understand when to use super until I watched this

domurtag
Автор

I've been working for 7 years as Java Developer . Most of the time we use "extends" generics. And "super" has been confused me till I watched that video. Big thank you sir!

dmitrystolbunov
Автор

I may have clapped when i FINALLY understood the concept (9:48) ! Glad you decided to make this video, Thank you sir !

radhikaganesan
Автор

Thank you Sean, learned more about super and extends today, love the example and the way you explained it.

sam
Автор

awesome explanations, it had been confusing until i saw this video, thanks for such explanations!

choudharysr
Автор

It was mega useful video even though I didn't understand it at first and second, but later...its 🔥🔥🔥

OS-sxyj
Автор

At 14:15, if we know we're getting passed potentially a list of Objects, or Animals, or Cats... why wouldn't we be able to add an Animal, as it's one of the options? Simply because we always have to take into consideration the potential for the narrowest type of all the possibilities passable (Cat), and covariance allows us for a list of Animals to have a Cat, but not a list of Cats to have an animal, so it has to do the safest thing in the direction of covariant happiness? As in: list<Object> can have Cats, list<Animal> can have cats, list<Cat> can have cats. So <? super Cat> is saying "Anything potentially as specific as a Cat"

ianokay
Автор

Very well explained with perfect example.!!!

rahilkhan
Автор

best of the best video. awesome explanations

axelrod
Автор

With PECS, i had a problem with understanding. It wasnt clear if the function produces the collection or produces from the collection. The extends == read-only it became easier to wrap it in my head. Thankyou.

kanthiswaroop
Автор

Thx for this great explanation. What I am missing from it, is the reason for such extends/super constructs, looking at all the things You can't (read/write) do with them. As I understood the limitations I am missing the argument why extends/super are helpful in certain cases. And maybe assuming certain roles (library programmer, library user)...

duesenberger
Автор

Hi, Sir Thanks for this explications excellent Glad for find you Kind regard

sagidelriego
Автор

Very informative. Thanks for sharing. I am still confused about Why ? extends Prevents Adding Elements and Why ? super Allows Adding Elements in java generics? And ? super Animal means it can hold either Animal or it's superclasses object then why would compiler allows to add Animal or it's subclasses (violating the purpose of super ) and there is not type safety here bcz the underlying arraylist could be of type Animal or it's super class. Compiler allowing us to modify the list making not type safe bcz I can add any subtype to the existing list.

pranithad
Автор

I am confused by the error you produce at 2:50-2:55. When I have the same set up i don't get an error.

furqaniqbal
Автор

can you plese explain liskow substitution principle using abstract classes and interfaces please?

sachin__ak