Java Generics Tutorial

  Рет қаралды 186,012

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
@deeptimonga7375
@deeptimonga7375 4 жыл бұрын
Keep On Making such videos on Keep On Coding channel. Really Helpful !!
@KeepOnCoding
@KeepOnCoding 4 жыл бұрын
Thanks for watching Deepti!
@TS-wj4im
@TS-wj4im 3 жыл бұрын
Dude thank you. My text book way over complicated generics. Now it all makes sense.
@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
@BoetFly
@BoetFly 4 жыл бұрын
Man, thank you so much, i finally understand those generics now :D
@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!
@conea6891
@conea6891 3 жыл бұрын
I like this fast paced explanation.
@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
@shagiwan
@shagiwan 2 жыл бұрын
Second year of studying Software Development in Uni and this is just the best explanation ive heard! Great job man!
@JosephGallagher
@JosephGallagher Жыл бұрын
This is the most concise and easy to understand video I've seen so far on Generics, thank you so much :D
@himanshushukla787
@himanshushukla787 3 жыл бұрын
bro your java playlist is so underrated. I love it
@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! 🤩
@chinemelumj5349
@chinemelumj5349 2 жыл бұрын
Finally understood generics, thank you so much!.
@philyeo
@philyeo 3 жыл бұрын
awesome stuff. I liked the way you explained it - showing the problem first and how generics can help save the day!
@fredericoamigo
@fredericoamigo 2 жыл бұрын
Thank you so much for this! I love your Java tutorials. So simple, clean and explanatory. Keep up the good work!
@lazpz617
@lazpz617 2 жыл бұрын
This video really helped me understand Generics way more than my instructors classes
@delmayank
@delmayank 4 жыл бұрын
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.
3 жыл бұрын
Wow! You explained it all so good. I finally feel like I understand this. Thank you so much. Please keep it coming.
@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
@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
@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
@athardaif
@athardaif 4 жыл бұрын
I was struggeling with understanding generics until I watched your video. Thanks a lot :)
@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
@ravenmadd1343
@ravenmadd1343 3 жыл бұрын
Why can't everything be explained this clearly and quickly? Thanks for doing this and keep up the good work.
@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!!
@shreypatel9379
@shreypatel9379 4 жыл бұрын
This was the best explanation on youtube, short and concise. Thank you and keep making such videos
@gauravkumarsingh640
@gauravkumarsingh640 4 жыл бұрын
This is legit the best video I could find to understand Generics!
@alexmedina5135
@alexmedina5135 4 жыл бұрын
what a good, easy, and elegant way to explain generics ... keep it up!!
@sheriffcrandy
@sheriffcrandy 4 жыл бұрын
You seem like just a solid dude haha thanks for the help man!
@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
@isah.2980
@isah.2980 3 жыл бұрын
Thank you so much! Please, keep doing videos like this!
@CarlosRamirez-uz7hs
@CarlosRamirez-uz7hs 3 жыл бұрын
Great video man, keep doing what you do
@prabhakarlal4799
@prabhakarlal4799 4 жыл бұрын
Nice and simplified explanation of a complicated topic. Thank you.
@PrakashVl
@PrakashVl 4 жыл бұрын
This tutorial is helpful for filling the gaps in generics, thanks for explaining thoroughly.
@anx007d
@anx007d 3 жыл бұрын
Thank You very much .. after looking many videos from different sources ....... this video absolutely cleared my thoughts for Java Generics.
@earl0fBronze
@earl0fBronze 4 жыл бұрын
I read a thirty page chapter on this, one ear out the other. This video is outstanding, mind blown.
@jiwonskitsch
@jiwonskitsch 4 жыл бұрын
Thank you for this quick video. You saved me 30 minutes of reading long paragraphs from my lecturers.
@ziekaman2450
@ziekaman2450 3 жыл бұрын
Thankyou so much. You're very talented in explaining complicated Java thingys!
@leonrickert4061
@leonrickert4061 4 жыл бұрын
Keep on man, cool teaching style
@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.
@lurkhidden9126
@lurkhidden9126 4 жыл бұрын
Learned hella! Good looks my guy
@19sunheart96
@19sunheart96 3 жыл бұрын
Nice video! Very easy to understand explanation of the concept.
@2010aishwary
@2010aishwary 4 жыл бұрын
very nice to the point video, subbed
@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!
@leeamraa
@leeamraa 8 ай бұрын
correction: you should make this function type-bounded as well, like this --> "boolean absEqual(NumericFns
@MrDoctorSchultz
@MrDoctorSchultz 4 жыл бұрын
Smooth, informative, and straight to the point. Keep up the good work!
@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.
@monetoast
@monetoast 4 жыл бұрын
Exceptional video, very clear!
@MrMarkjams
@MrMarkjams 4 жыл бұрын
This is a great video! Could you do one on Interfaces?
@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
@kylemanley915
@kylemanley915 4 жыл бұрын
Sweet tutorial, just subscribed
@RubenGarciaCS
@RubenGarciaCS 3 жыл бұрын
Excellent quality! Thank you
@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)
@fahadtahir6
@fahadtahir6 4 жыл бұрын
Very informative and loved your communication style
@abhijeetmokale9024
@abhijeetmokale9024 4 жыл бұрын
Seriously this way of learning from the problem is amazing! Thanks Sir!!
@aavocadoToast
@aavocadoToast 3 жыл бұрын
Great video! Detailed and to the point.
@tarunkaushik320
@tarunkaushik320 3 ай бұрын
Very well! Nice explanation of usages of Generic types, and Wildcards.👌(helps in understanding the difference between them and their significance)
@morolillyshean8816
@morolillyshean8816 2 жыл бұрын
Yes, this is the best one I found. Thanks!
@ledtargaouschi5831
@ledtargaouschi5831 4 жыл бұрын
Your videos are very helpful and your teaching methods are very clear
@davidxdhloqud
@davidxdhloqud 2 жыл бұрын
I'm spanish speaker, your videos are sooo good than I can understand, thank you
@AshBeastreal
@AshBeastreal 3 жыл бұрын
Wow this is one of the best explainer videos. Loved watching it🤩
@89pravinb
@89pravinb 3 жыл бұрын
Thank you for creating this video! Very concise and informative
@qwarlockz8017
@qwarlockz8017 3 жыл бұрын
Nice video. You do have a great way of explaining things.
@kanonlast8241
@kanonlast8241 3 жыл бұрын
excellent explanation... got you loud and clear... but how did you turn on the lights at the back just by clicking...
@GeorgeKonstantinou-v2i
@GeorgeKonstantinou-v2i 3 жыл бұрын
well thank you for explaining to me what i didn't learn from the class.
@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 :)
@damyandimitrov611
@damyandimitrov611 4 жыл бұрын
Very well explanation and approach
@ItsTheDannyShow
@ItsTheDannyShow 4 жыл бұрын
Subscribing man. You helped so much.
@olegc6209
@olegc6209 4 жыл бұрын
Awesome explanation, thanks for your help!
@tetsuorulin9009
@tetsuorulin9009 3 жыл бұрын
I love teaching to the problem. Great video and thanks!
@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?
@xxanton8xx
@xxanton8xx 4 жыл бұрын
You look like you're gonna fall asleep the next second, but you explained the topic very well!
@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).
@nisarullah7734
@nisarullah7734 3 жыл бұрын
Great work keep it up
@anithachowdary9716
@anithachowdary9716 4 жыл бұрын
I understood the topic very well.Thank you so much Please share more videos
@donwinston
@donwinston 7 ай бұрын
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.
@kirankumarmothukuri7660
@kirankumarmothukuri7660 4 жыл бұрын
Good explanation bro. By the by which company are you working right now bro? amazon, google?
@faikyesilyaprak8761
@faikyesilyaprak8761 4 жыл бұрын
That was lit bro!!!! Thanks for crystal clear explanation :))))
@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!
@pratikthorat3480
@pratikthorat3480 3 жыл бұрын
I know what generics are but I still feel I learnt a few new things here. God Dayummm you are awesome.
@TKollaKid
@TKollaKid 3 жыл бұрын
Great explanation - clear and helpful. Thank you.
@kalyanmatamarugu9396
@kalyanmatamarugu9396 4 жыл бұрын
Clean, simple and perfect content!
@arnabmukherjee5840
@arnabmukherjee5840 4 жыл бұрын
Awesome tutorial bro
@xsendilien9551
@xsendilien9551 4 жыл бұрын
Really awesome bro!
@999loaderu
@999loaderu 3 жыл бұрын
really well explained m8. Appreciate it. thx
@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!
@technoultimategaming2999
@technoultimategaming2999 3 жыл бұрын
okay that is pretty cool. You have no idea how many times I want to do something yet the data type is undefined
@wenbozhang8192
@wenbozhang8192 4 жыл бұрын
Thanks for the clear and straightforward class. BTW, could you share the background music?
@KeepOnCoding
@KeepOnCoding 4 жыл бұрын
Fly me high by Harris Heller
@dablo898
@dablo898 4 жыл бұрын
Thank you, I learnt something new today
@premalupadhyay3555
@premalupadhyay3555 4 жыл бұрын
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!
@temps1959
@temps1959 3 жыл бұрын
11:17 would it be better practice to say ‘(NumericFns
@nikeshparajuli6345
@nikeshparajuli6345 4 жыл бұрын
it's really helpful,thanks a lot .
@kennethfrederickx
@kennethfrederickx 3 жыл бұрын
wish my teacher knew how to explain this like u, great video
@leslyp.blaise7238
@leslyp.blaise7238 3 жыл бұрын
Explanation clear and concise thank you
@toniiicarbonelll287
@toniiicarbonelll287 4 жыл бұрын
MAAAAAAAAAAAAAAAAAN that was just awesome thank you very much!
Generics In Java - Full Simple Tutorial
17:34
Coding with John
Рет қаралды 1,1 МЛН
Java Interface Tutorial
14:49
Keep On Coding
Рет қаралды 143 М.
Who is More Stupid? #tiktok #sigmagirl #funny
0:27
CRAZY GREAPA
Рет қаралды 10 МЛН
UFC 287 : Перейра VS Адесанья 2
6:02
Setanta Sports UFC
Рет қаралды 486 М.
The Biggest React Framework You've Never Heard of
20:29
Theo - t3․gg
Рет қаралды 52 М.
Object Oriented Programming - The Four Pillars of OOP
11:23
Keep On Coding
Рет қаралды 361 М.
Learn Java GENERICS in 13 minutes! 📦
13:56
Bro Code
Рет қаралды 4,3 М.
Array List vs Linked List | Which one should you use??
7:57
Keep On Coding
Рет қаралды 58 М.
Java generics ❓
22:04
Bro Code
Рет қаралды 122 М.
Java Classes & Objects
11:36
Keep On Coding
Рет қаралды 383 М.
LinkedList vs ArrayList in Java Tutorial - Which Should You Use?
11:43
Coding with John
Рет қаралды 620 М.
Java Exception Handling Tutorial
11:39
Keep On Coding
Рет қаралды 83 М.
Meta Interview Experience 2024 | Software Engineer
9:55
Keep On Coding
Рет қаралды 60 М.
Who is More Stupid? #tiktok #sigmagirl #funny
0:27
CRAZY GREAPA
Рет қаралды 10 МЛН