Java Generics Tutorial

  Рет қаралды 185,577

Keep On Coding

Keep On Coding

Күн бұрын

Пікірлер: 303
@KeepOnCoding
@KeepOnCoding 4 жыл бұрын
☕Want to master Java? Get my complete Java course: bit.ly/42mQlXE
@KnakuanaRka
@KnakuanaRka 4 жыл бұрын
Also, something else to add about generics: If you’re expecting some specific property of the class you put into a generic, you can write that into your generic. For example, if your class had an array of T’s that you wanted to sort, just putting MyClass will make your compiler complain that you’re doing something unsafe. This is because you can only use sort() on the array if the class T implements the Comparable interface and its compareTo() method, and there’s no guarantee someone won’t try to make it with some class Java doesn’t know how to compare or sort (like a custom one). The solution here? Write your class header as MyClass. This tells the compiler that you will only make MyClass’es with types that can be sorted. This uses “extends” as opposed to the “implements” usually used for interfaces because you’re just making a promise about the generic class, not actually implementing one, and the second T is because Comparable is also generic (so you need to say that T implements a method to compare T objects specifically).
@eustachybakielka
@eustachybakielka 4 жыл бұрын
It's not because of reification of arrays?
@KnakuanaRka
@KnakuanaRka 4 жыл бұрын
@@eustachybakielka Not sure what you’re referring to.
@eustachybakielka
@eustachybakielka 4 жыл бұрын
@@KnakuanaRka "For example, if your class had an array of T’s that you wanted to sort, just putting MyClass will make your compiler complain that you’re doing something unsafe"
@KnakuanaRka
@KnakuanaRka 4 жыл бұрын
@@eustachybakielka What the heck is reification of arrays?
@eustachybakielka
@eustachybakielka 4 жыл бұрын
@@KnakuanaRka What is reification in Java? In the context of Java as a programming language, reification is the process by which a user program or any aspect of a programming language that was implicit in the translated program and the run-time system, are expressed in the language itself. In Java, there exist "reifiable types" that are "completely available at run time" (i.e. their information is not erased during compilation). Example: //Allocates an array of type String, so it is reified String[] aStringArray = new String[10]; //Allocates a list with no type, Java does not reify generic types List aStringList = new ArrayList();
@lindawisebear
@lindawisebear 4 жыл бұрын
This is the best explanation of Generics I've seen on the internet. I loved how you started with the problem to solve, and then showed how generics is useful when tackling that problem :)
@999loaderu
@999loaderu 3 жыл бұрын
true dat. Fell the same
@gauravmishra8782
@gauravmishra8782 2 жыл бұрын
True
@philippebaillargeon5204
@philippebaillargeon5204 4 жыл бұрын
I like the way you explain things: Java developers created Generics to solve a problem, so I think its pretty logical to talk about the problem before talking about the concepts that were created to solve it. Great video !
@mastershonobi110
@mastershonobi110 3 жыл бұрын
Super great point(illustrate the problem to solve, before the concept). A lot of Java Channels should be taking notes!!
@angledcoathanger
@angledcoathanger 2 жыл бұрын
Totally agree - it's hard to get excited about a key if you haven't seen the lock that it opens
@TS-wj4im
@TS-wj4im 3 жыл бұрын
Dude thank you. My text book way over complicated generics. Now it all makes sense.
@abdullahmajed7554
@abdullahmajed7554 4 жыл бұрын
that was really simple i love the way you edit the video making switch between you and the code it feels so clean, thank you
@deeptimonga7375
@deeptimonga7375 4 жыл бұрын
Keep On Making such videos on Keep On Coding channel. Really Helpful !!
@KeepOnCoding
@KeepOnCoding 4 жыл бұрын
Thanks for watching Deepti!
@dalvandi
@dalvandi 4 жыл бұрын
Possibly one of the best, clearest, and crispest explanations on the generic class that I've seen! Keep up the great content dude!
@ramiayash7658
@ramiayash7658 3 жыл бұрын
i highly agree with you, the guy is so clear with his explanations
@shagiwan
@shagiwan 2 жыл бұрын
Second year of studying Software Development in Uni and this is just the best explanation ive heard! Great job man!
@IgorBeneli1014
@IgorBeneli1014 4 жыл бұрын
You're incredible you explained with 12min a concept that my professor couldn't do it with 1 hour. Keep doing this amazing job thank you so much!
@JosephGallagher
@JosephGallagher Жыл бұрын
This is the most concise and easy to understand video I've seen so far on Generics, thank you so much :D
@conea6891
@conea6891 3 жыл бұрын
I like this fast paced explanation.
@mohannadfadhal4282
@mohannadfadhal4282 3 жыл бұрын
Thank you so much, Sir. You made the explanation for generics very simplified, especially, by the style of starting with the problem first and then showing the solution! 🤩
@himanshushukla787
@himanshushukla787 3 жыл бұрын
bro your java playlist is so underrated. I love it
@philyeo
@philyeo 3 жыл бұрын
awesome stuff. I liked the way you explained it - showing the problem first and how generics can help save the day!
@delmayank
@delmayank 3 жыл бұрын
Lounge Coding! I really liked the theme. A new touch to coding tutorials. I am your fan now. You rock! Oh! And the stuff that you covered in this tutorial is of great value. You explained it easily and flawlessly.
@fredericoamigo
@fredericoamigo 2 жыл бұрын
Thank you so much for this! I love your Java tutorials. So simple, clean and explanatory. Keep up the good work!
@anx007d
@anx007d 3 жыл бұрын
Thank You very much .. after looking many videos from different sources ....... this video absolutely cleared my thoughts for Java Generics.
@tarunkaushik320
@tarunkaushik320 2 ай бұрын
Very well! Nice explanation of usages of Generic types, and Wildcards.👌(helps in understanding the difference between them and their significance)
@lazpz617
@lazpz617 2 жыл бұрын
This video really helped me understand Generics way more than my instructors classes
3 жыл бұрын
Wow! You explained it all so good. I finally feel like I understand this. Thank you so much. Please keep it coming.
@chinemelumj5349
@chinemelumj5349 2 жыл бұрын
Finally understood generics, thank you so much!.
@hannahc8436
@hannahc8436 2 жыл бұрын
This was such a great explanation of Generics. I've been so confused about it for the past few weeks. Thank you!!
@BoetFly
@BoetFly 4 жыл бұрын
Man, thank you so much, i finally understand those generics now :D
@wovasteengova
@wovasteengova 4 жыл бұрын
This looks like it's from java, a beginner's guide. I too was confused on what generics fix but thank you for explaining it in the beginning of the video. I think you should do that to all your videos
@SaljooqAltaf
@SaljooqAltaf 4 жыл бұрын
This just might be personal preference but the best and most detailed explanations for anyone studying comp sci are found in this channel - no idea why views haven't hit a million
@shreypatel9379
@shreypatel9379 4 жыл бұрын
This was the best explanation on youtube, short and concise. Thank you and keep making such videos
@alexmedina5135
@alexmedina5135 4 жыл бұрын
what a good, easy, and elegant way to explain generics ... keep it up!!
@ziekaman2450
@ziekaman2450 3 жыл бұрын
Thankyou so much. You're very talented in explaining complicated Java thingys!
@gauravkumarsingh640
@gauravkumarsingh640 4 жыл бұрын
This is legit the best video I could find to understand Generics!
@AshBeastreal
@AshBeastreal 2 жыл бұрын
Wow this is one of the best explainer videos. Loved watching it🤩
@19sunheart96
@19sunheart96 3 жыл бұрын
Nice video! Very easy to understand explanation of the concept.
@PrakashVl
@PrakashVl 4 жыл бұрын
This tutorial is helpful for filling the gaps in generics, thanks for explaining thoroughly.
@prabhakarlal4799
@prabhakarlal4799 4 жыл бұрын
Nice and simplified explanation of a complicated topic. Thank you.
@ravenmadd1343
@ravenmadd1343 3 жыл бұрын
Why can't everything be explained this clearly and quickly? Thanks for doing this and keep up the good work.
@101matthias
@101matthias 4 жыл бұрын
I just watched 9 hours of online classes from my teacher on generics and I understood nothing. Less than nothing. 10 minutes of you and everything is clear it's super easy actually.
@technocoh
@technocoh 2 жыл бұрын
yeah not every professional or teacher is able to share his knowledge the proper way... ;)
@pinolskun8764
@pinolskun8764 2 жыл бұрын
@@technocoh yeah if someone need 9 hours to explain a concept you can safely assume they are the first who don't understand it
@earl0fBronze
@earl0fBronze 4 жыл бұрын
I read a thirty page chapter on this, one ear out the other. This video is outstanding, mind blown.
@abdullahmoiz8151
@abdullahmoiz8151 4 жыл бұрын
Man this was a fantastic explanation I particularly liked how you first showed what the problem was then showed how generics solve it
@leeamraa
@leeamraa 7 ай бұрын
correction: you should make this function type-bounded as well, like this --> "boolean absEqual(NumericFns
@athardaif
@athardaif 4 жыл бұрын
I was struggeling with understanding generics until I watched your video. Thanks a lot :)
@KeepOnCoding
@KeepOnCoding 4 жыл бұрын
Have you ever used Generics in your code?
@Jilnn
@Jilnn 4 жыл бұрын
nope
@Chaz-LeeP
@Chaz-LeeP 4 жыл бұрын
yea! coming from c++, i was taught that its called templates
@ActualVital
@ActualVital 4 жыл бұрын
Yup. My Data Structures professor would always require us to use them. Still don’t understand them. Hopefully this video will help me understand!
@guitarman813
@guitarman813 4 жыл бұрын
Yes, in my latest Java project. While they seem easy in theory, implementing them is another matter! I hope to gain knowledge from this video and other sources and thus strengthening my performance in this area.
@rossocorsa6577
@rossocorsa6577 4 жыл бұрын
Keep On Coding Yee for my assigment
@ledtargaouschi5831
@ledtargaouschi5831 4 жыл бұрын
Your videos are very helpful and your teaching methods are very clear
@shecodesthings3978
@shecodesthings3978 4 жыл бұрын
Ah, another example of my previous compsci professors failing to teach something fairly straightforward... *facepalm* You, on the other hand, taught it in such a practical and applicable manner: Discuss a simple problem and then propose a solution (and actually working through the example) Super easy to remember too. Great video!
@kaifahsan8459
@kaifahsan8459 4 жыл бұрын
Thanks for the video mate. Pretty well explained. Would be awesome if you keep making videos about core and advanced OOP concepts like this.
@KeepOnCoding
@KeepOnCoding 4 жыл бұрын
Thank you sir. Did you have a specific topic in mind?
@kaifahsan8459
@kaifahsan8459 4 жыл бұрын
Probably topics like interfaces, polymorphism, exceptions, collection frameworks etc. There's a huge Quora thread that might help you as well: www.quora.com/What-is-a-complete-list-of-topics-of-Core-Java-and-topics-of-Advanced-Java
@KeepOnCoding
@KeepOnCoding 4 жыл бұрын
Awesome! Thanks!
@youvegotmail9385
@youvegotmail9385 2 жыл бұрын
Not sure why it's still taking me a minute to wrap my head around Generics. I'm sure it'll click, but it's so funky to me even with your great explanation.
@isah.2980
@isah.2980 3 жыл бұрын
Thank you so much! Please, keep doing videos like this!
@abhijeetmokale9024
@abhijeetmokale9024 4 жыл бұрын
Seriously this way of learning from the problem is amazing! Thanks Sir!!
@nyangnyangliz
@nyangnyangliz 4 жыл бұрын
Thank you for this quick video. You saved me 30 minutes of reading long paragraphs from my lecturers.
@CarlosRamirez-uz7hs
@CarlosRamirez-uz7hs 3 жыл бұрын
Great video man, keep doing what you do
@davidxdhloqud
@davidxdhloqud 2 жыл бұрын
I'm spanish speaker, your videos are sooo good than I can understand, thank you
@leonrickert4061
@leonrickert4061 4 жыл бұрын
Keep on man, cool teaching style
@quikel7045
@quikel7045 2 жыл бұрын
Watched 2 videos, had it at uni, read documentation and still didn't understand why Wildcards are useful. You basically explained it in 2min with a simple example. Thank you very much.
@fahadtahir6
@fahadtahir6 4 жыл бұрын
Very informative and loved your communication style
@zachhewitt4328
@zachhewitt4328 4 жыл бұрын
10/10 man! Keep it up. It's better than my current professor!
@KeepOnCoding
@KeepOnCoding 4 жыл бұрын
Lol glad it helped!
@tolstoievski4926
@tolstoievski4926 3 жыл бұрын
You can also declare generic type at method scope id you're planning to use static methods (methods that are not requiring you to instantiate class to use it)
@sheriffcrandy
@sheriffcrandy 4 жыл бұрын
You seem like just a solid dude haha thanks for the help man!
@anithachowdary9716
@anithachowdary9716 4 жыл бұрын
I understood the topic very well.Thank you so much Please share more videos
@monetoast
@monetoast 4 жыл бұрын
Exceptional video, very clear!
@saintfrancisbeats9639
@saintfrancisbeats9639 4 жыл бұрын
Dope! I am currently in an Intermediate Programming college course and they just want us to read a document. I was so lost. This clarified alot. Also it cause me to switch from Netbeans to IntelliJ IDEA hahaha
@tetsuorulin9009
@tetsuorulin9009 3 жыл бұрын
I love teaching to the problem. Great video and thanks!
@pratikthorat3480
@pratikthorat3480 3 жыл бұрын
I know what generics are but I still feel I learnt a few new things here. God Dayummm you are awesome.
@2010aishwary
@2010aishwary 4 жыл бұрын
very nice to the point video, subbed
@qwarlockz8017
@qwarlockz8017 3 жыл бұрын
Nice video. You do have a great way of explaining things.
@89pravinb
@89pravinb 3 жыл бұрын
Thank you for creating this video! Very concise and informative
@faikyesilyaprak8761
@faikyesilyaprak8761 4 жыл бұрын
That was lit bro!!!! Thanks for crystal clear explanation :))))
@premalupadhyay3555
@premalupadhyay3555 3 жыл бұрын
Great and simple explanation, I like this way of teaching a lot.
@liaskarllate
@liaskarllate 4 жыл бұрын
WOW' You're good at teaching code and concepts. Way to go!
@lurkhidden9126
@lurkhidden9126 4 жыл бұрын
Learned hella! Good looks my guy
@RubenGarciaCS
@RubenGarciaCS 3 жыл бұрын
Excellent quality! Thank you
@morolillyshean8816
@morolillyshean8816 2 жыл бұрын
Yes, this is the best one I found. Thanks!
@aavocadoToast
@aavocadoToast 3 жыл бұрын
Great video! Detailed and to the point.
@kylemanley915
@kylemanley915 4 жыл бұрын
Sweet tutorial, just subscribed
@ritexcorp
@ritexcorp 2 жыл бұрын
That was a great explanation of Generics, keep up the good work, I just subscribed to your channel. Do you have something on Java annotations?
@MrDoctorSchultz
@MrDoctorSchultz 4 жыл бұрын
Smooth, informative, and straight to the point. Keep up the good work!
@olegc6209
@olegc6209 4 жыл бұрын
Awesome explanation, thanks for your help!
@TKollaKid
@TKollaKid 3 жыл бұрын
Great explanation - clear and helpful. Thank you.
@damyandimitrov611
@damyandimitrov611 4 жыл бұрын
Very well explanation and approach
@AlbatraozProductions
@AlbatraozProductions 3 жыл бұрын
Great video! If I can be a bit nitpicky, you should call "functions" by their real Java name, "methods". I know this is a really small detail, but since many people who watch these kind of videos might be pretty new to Java, it can help prevent confusion.
@mattrazol
@mattrazol 4 жыл бұрын
Hello there! In the last example.. what about if, instead of using the question mark (therefore a generic object), you declare another generic type (let's say V) that also extends Number? Something like this: boolean absEqual(NumericFns num) { ... } Therefore you can ensure that for example a string (or any other object that doesn't extend Number) wont be passed, and potentially break your code? I'd be glad to hear your opinion on it. 😃
@gaspartomi971
@gaspartomi971 4 жыл бұрын
Late answer, but here it is! What you suggest is unnecessary, since the class NumericFns can only be constructed with a number class argument anyways. So that parameter has a ? as argument, thats true, but it is impossible for that ? to not be a number (NumericFns constructor wont allow it).
@ItsTheDannyShow
@ItsTheDannyShow 4 жыл бұрын
Subscribing man. You helped so much.
@chikken007
@chikken007 4 жыл бұрын
Great explanation! Just gained a new Sub. Thank you and keep it up please!
@donwinston
@donwinston 6 ай бұрын
You didn't cover generic methods and the parameter type lists before the returned type in a method definition. I've been using generics for years and just learned this today! Don't have to use this when you're just a consumer of generic classes.
@furioustodd5105
@furioustodd5105 4 жыл бұрын
I have always found Generics a hard topic. Your explanation with code was great. Huge thumbs up 👍🏻
@999loaderu
@999loaderu 3 жыл бұрын
really well explained m8. Appreciate it. thx
@leslyp.blaise7238
@leslyp.blaise7238 3 жыл бұрын
Explanation clear and concise thank you
@kalyanmatamarugu9396
@kalyanmatamarugu9396 4 жыл бұрын
Clean, simple and perfect content!
@kennethfrederickx
@kennethfrederickx 3 жыл бұрын
wish my teacher knew how to explain this like u, great video
@bibahbibah5108
@bibahbibah5108 3 жыл бұрын
i like the u develop the subject, uake java very easy to work with
@lancelotlin3459
@lancelotlin3459 4 жыл бұрын
Best tutorial! Thanks for your explanation!
@jschlln206
@jschlln206 3 жыл бұрын
Am I the only one who's confused as to why a generic number class defaulted to requiring an integer (11:08)? Great video, as usual!
@xxanton8xx
@xxanton8xx 4 жыл бұрын
You look like you're gonna fall asleep the next second, but you explained the topic very well!
@GeorgeKonstantinou-v2i
@GeorgeKonstantinou-v2i 3 жыл бұрын
well thank you for explaining to me what i didn't learn from the class.
@nisarullah7734
@nisarullah7734 3 жыл бұрын
Great work keep it up
@dablo898
@dablo898 4 жыл бұрын
Thank you, I learnt something new today
@Laa_
@Laa_ 2 жыл бұрын
Hello, thank you for tutorial, it helped me a lot about generics. But I have a question. On 10:50 you said num will always have to be an integer. Question is simple. Why? I thought num is data type of T and T is extending numbers so it can be an integer as well as a double and so on. Thank you in advance :)
@himangshuchowdhary4369
@himangshuchowdhary4369 2 жыл бұрын
Great explanation KOC!
@Burak-cr6um
@Burak-cr6um 2 жыл бұрын
Thank you, It was very helpful as usual.
@temps1959
@temps1959 3 жыл бұрын
11:17 would it be better practice to say ‘(NumericFns
@wesNeill
@wesNeill 3 жыл бұрын
Lol @ the smooth jazz in the background. But good content!
@MrMarkjams
@MrMarkjams 4 жыл бұрын
This is a great video! Could you do one on Interfaces?
Generics In Java - Full Simple Tutorial
17:34
Coding with John
Рет қаралды 1,1 МЛН
Object Oriented Programming - The Four Pillars of OOP
11:23
Keep On Coding
Рет қаралды 357 М.
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
Java generics ❓
22:04
Bro Code
Рет қаралды 120 М.
Learn Java in 15 Minutes (seriously)
19:50
ForrestKnight
Рет қаралды 164 М.
Java Interface Tutorial
14:49
Keep On Coding
Рет қаралды 142 М.
Array List vs Linked List | Which one should you use??
7:57
Keep On Coding
Рет қаралды 58 М.
Learn Java GENERICS in 13 minutes! 📦
13:56
Bro Code
Рет қаралды 2,4 М.
Interview Question | Comparable vs Comparator in Java
12:58
Telusko
Рет қаралды 649 М.
TypeScript Generics are EASY once you know this
22:21
ByteGrad
Рет қаралды 146 М.
Generics in Java - Full Tutorial
20:08
Daily Code Buffer
Рет қаралды 29 М.
Java Generics Explained
13:45
Jack Hodkinson
Рет қаралды 47 М.
Vectors in Java: The 1 Situation You Might Want To Use Them
16:13
Coding with John
Рет қаралды 87 М.