Generics and Wildcards in Java | Part 1 | Generics with Wildcards in Java Made Simple | Geekific
Вставка
- Опубліковано 7 лип 2024
- Support us on Patreon: / geekific
GitHub Repository: github.com/geekific-official/...
Stay updated on our videos by subscribing to the channel and hitting the like button!
In this video we cover Java Generics and Wildcards. Additionally, we answer why and when you should make use of them while developing an application or writing any piece of code.
Timestamps:
00:00 Introduction
00:25 What are Generics?
02:29 Implementing Generics in Java
03:38 What are Wildcards?
05:07 Bounded Generics and Wildcards
07:27 Why can't primitive types be used with Generics?
08:08 Recap
08:27 Thanks for Watching!
If you found this video helpful, check other Geekific uploads:
- Must Know Java Keywords!: • Must Know Java Keyword...
- Association, Aggregation and Composition Explained: • UML Class and Object D...
- Generics and Wildcards in Java Made Simple: • Generics and Wildcards...
- LinkedList Implementation in Java: • Implementing the Linke...
- Functional Interfaces and Lambda Expressions in Java: • Functional Interfaces ...
- Java Streams Explained with Examples: • Java Stream API Explai...
- Object-Oriented Programming Fundamentals: • What is Object-Oriente...
#Geekific #Generics #Wildcards #Java
Thank you so much for this. The first good explanation of wildcards I have seen so far!
Why shouldnt i always use Wilcards? and just bound to a specific Type
I am so happy that I've found your channel, your videos are super informative and everything is very well explained, keep it up
Thank you! Glad I could help :)
Well done. I had a question and you answered it 100%. Awesome video. Thanks.
Glad I did! Happy to help :)
thanks for the explanation!
GREAT EXPLANATION !!!!
Great videos. Live them ❤
You are very good at explaining. For the future, maybe you can look at providing realtime problems and solutions to deepen our understanding further. Other than that, excellent video!
Thanks a lot, happy you liked it! And great suggestion will keep it in mind for the future :)
wow this was so well explained thanks for the video!!
Thank you!
you are the best your video saved me ily
You are so good , finally I understood wildcards
Glad it helped!
It was very helpful. Great job!
Glad! Thank you!
Extremely helpful video !!
Glad you think so!
This is gold.
Thanks a lot! Your words are gold to me :)
thx, now I understand.
Glad I could help! :)
nice video
Great and Simple to the point !! One question though, u mean Generics are class wise and wildcards are for Method wise boundaries ? is there any other difference further ..
Generics can actually be used for methods as well as for classes, when we do so the method is called a generic method, so the type parameter will be tied to the method alone and not the class. However, making use of the wildcard at class level won't really make sense, your code won't compile. Wildcards are used in Java to handle variance, and you can't create a class if you don't know what attributes it defines! We will be covering all these in a part 2 Generics video, stay tuned!
Hope this answers your question :) Cheers!
Hello I am remaking data structures to better understand how to use them. Can you explain wild cards used in the class level like this: public class MaxPriorityQueue
Hello, we will be uploading a video Part 2 that dives in the details of generics and should answer all of your questions regarding this topic! Stay Tuned!
No ? super T explanation thumbs down
Thanks for the review! However, am not sure what seems to be the problem or which parts of the video weren't clear, can you elaborate so we can fix it?
@@geekific u only explained
You are right :) We'll be working on a part 2 generics video to expand further on the subject! Stay Tuned!
And meanwhile, as a quick answer to your question: 'extends' means that the generic type (?) has to be a subclass of T, however, 'super' means that the generics type has to be a super class of T, in other terms it is T that extends the generic type (T represents the lower bound here). Hope this helps. Cheers!
@@geekific Got it; but when should I be using which? And why in the documentation there are methods that use super? For example, the Stream interface has the method forEach, that takes a "Consumer
Okay, the fully detailed answer will have to wait for the video, but in short remember PECS (Producer extends, Consumer super). When you are producing or "reading" use extends, when you are consuming or "writing" go for super and if you need both do not use a wildcard just T. They make your code more flexible by allowing the use of subtypes and supertypes when needed. Stay tunned for more details in an upcoming video!