// Generic method public static void displayArray(Thing[] array) { for(Thing x : array) { System.out.print(x+" "); } System.out.println(); }
// Generic method with generic return type public static Thing firstIndex(Thing[] array) { return array[0]; } } //----------------------- Generic Class ----------------------- public class Main { public static void main(String args[]) {
//bounded types = you can create the objects of a generic class to have data // of specific derived types ex.Number
MyGenericClass myInt = new MyGenericClass(1,9); MyGenericClass myDouble = new MyGenericClass(3.14,1.01); //MyGenericClass myChar = new MyGenericClass('@','$'); //MyGenericClass myString = new MyGenericClass("Hello",'!');
System.out.println(myInt.getValue()); System.out.println(myDouble.getValue()); //System.out.println(myChar.getValue()); //System.out.println(myString.getValue()); } } // ---------------------------------------------------------------- public class MyGenericClass { Thing x; Thing2 y;
Bro this was the heaviest video of all till now ! Literally my brain just exploded ! But extremely simple and direct - So thank you for such a badass of a teacher
Wow, I'm glad I found your channel. You style is crystal clear and to the point. Although I'm taking other classes you clarify the points I was having trouble with. Thanks man!
Finally after spending 2 days reading the chapter and going over rigerious examples and still being clueless, I've understood generics. Love the channel name 😁
really thx bro, though i'm watched some videos about generics, i'm still struggling with its use, here's some examples also other videos i watched but i'm not got a good understanding until you open the ArrayList class, everything is clear, i got the key point , this is really a nice video
Can you create a generic arraylist to hold multiple types, for example: ArrayList newList = new ArrayList(); ??? Thanks for video, explained very well.
i am a fellow bro 😎, bro code plaese keep creating videos about java, there are very less content on youtube about java, everyone is posting videos about python , javascript but no one explaining java🥲 , thank you bro.
Well, Technically yes we can but there are so many disadvantages when using Object class, But if we use Generics its not complicated as Object. And also Generics is flexible and safe. At the same time, when we are working with Object it requires type-casting which lead us to so many errors.
//----------------------- Generic Method -----------------------
public class Main {
public static void main(String args[]) {
Integer[] intArray = {1, 2, 3, 4, 5};
Double[] doubleArray = {5.5, 4.4, 3.3, 2.2, 1.1};
Character[] charArray = {'H', 'E', 'L', 'L', 'O'};
String[] stringArray = {"B","Y","E"};
System.out.print("Integer Array: ");
displayArray(intArray);
System.out.println(firstIndex(intArray));
System.out.print("Double Array: ");
displayArray(doubleArray);
System.out.println(firstIndex(doubleArray));
System.out.print("Character Array: ");
displayArray(charArray);
System.out.println(firstIndex(charArray));
System.out.print("String Array: ");
displayArray(stringArray);
System.out.println(firstIndex(charArray));
*/
}
// Generic method
public static void displayArray(Thing[] array) {
for(Thing x : array) {
System.out.print(x+" ");
}
System.out.println();
}
// Generic method with generic return type
public static Thing firstIndex(Thing[] array) {
return array[0];
}
}
//----------------------- Generic Class -----------------------
public class Main {
public static void main(String args[]) {
//bounded types = you can create the objects of a generic class to have data
// of specific derived types ex.Number
MyGenericClass myInt = new MyGenericClass(1,9);
MyGenericClass myDouble = new MyGenericClass(3.14,1.01);
//MyGenericClass myChar = new MyGenericClass('@','$');
//MyGenericClass myString = new MyGenericClass("Hello",'!');
System.out.println(myInt.getValue());
System.out.println(myDouble.getValue());
//System.out.println(myChar.getValue());
//System.out.println(myString.getValue());
}
}
// ----------------------------------------------------------------
public class MyGenericClass {
Thing x;
Thing2 y;
MyGenericClass(Thing x, Thing2 y){
this.x = x;
this.y = y;
}
public Thing2 getValue() {
return y;
}
}
thank you so much
love u bro
forever subscriber
Single-handedly taught me Generics and helped me complete an assignment in 30 minutes. Epic!
The best tutorials, I've ever seen on YT, thx bro!!!
Let start a campaign to give bro best teacher on youtube award !!!!!
❤❤❤❤❤❤❤ .
I always go through one of these videos before starting my bootcamp lessons. It makes everything so much easier to get into.
Excellent tutorial video about generic classes and methods!
Bro this was the heaviest video of all till now ! Literally my brain just exploded ! But extremely simple and direct - So thank you for such a badass of a teacher
My professor sucks and ever since I started coming here instead of their lectures, my grade went from a B to an A. Thank you Brofessor!
You, my dear Sir, are a legend. Thank you so much for all these incredibly useful instructional videos.
a lot of new stuff but really well explained, thanks!
you have really the best tutorials I have ever seen, thank you. greetings from germany
Thanks, I finally understand Generics, some code training/bootcamps explain it really complicated.. but with you i realized it's just that simple.
That 1 dislike is from bro himself, just to keep himself humble... ;)
Well said Bro, you did exactly what we want. The Duration with perfect explanation, great effort that you spend on it. It pay off man. Good Luck ...
Wow, I'm glad I found your channel. You style is crystal clear and to the point. Although I'm taking other classes you clarify the points I was having trouble with. Thanks man!
this channel is a gold mine
This would be the best java tutorial videos out there. Thank you bro
very clear and comprehensive. thank you again.
Your code is so clean. You really know what you are doing!!!!
You are so smart to simplify such big task in a simple ways
Thank you bro!
Of Eritrea 🇪🇷
I just learned more from a twenty minute video than a two hour lecture from my professor. You have a new bro.
Really the best tutorials on UA-cam, that I've seen, keep up the good work Bro!
well explained especially that part of where you can use 'Thing' instead of 'T' clears the mystery behind why is it always T,E or S.
Thanks again for another relatively simple concept explained in a brilliant way.
most helpful generics video on the internet. hands down
concept cleared 🙌 Thanks Bro...and you have an unique way of explaining the things.
Finally after spending 2 days reading the chapter and going over rigerious examples and still being clueless, I've understood generics. Love the channel name 😁
Yes, his chanel is very good!
His channel is not generic
You are the best !!! Thanks for lessons in 2023
Good job bro. That's exactly how you teach sth. I'm very glad that I found this amazing channel. Keep going on
Self learning but I understand easily ,this guy is awesome...
unparalleled at teaching, thanks bro
THE BEST EVER EXPLENATION OF GENERIC CLASS AND METHODS IN UA-cam HISTORY🤣
Thank you so much for your simplified explanation . Straight to the point.
The best video for Generics I have ever seen, and the examples are pretty nice!
wow that's a lot of stuff in one tutorial 🤯👍
Wow! Generic is so damn useful. I wish i saw this video yesterday lol but still, better than never. Well explained too
what the hell so good java tutorial i ever saw in youtube. thank you very much!
Thank you for this very helpful video
I learnt lot of things so far from the above 83 videos
Best tutorials ever, holy shit it's pleasant to learn looking your videos bro, keep going !
Very clear explanation. My first clear understanding comes from you. Thanks a lot. ;)
I was rejected in interview cause i didnt know what is generics and i saw that in their code xd, i saw many in a generic method. Thx
really thx bro, though i'm watched some videos about generics, i'm still struggling with its use, here's some examples also other videos i watched but i'm not got a good understanding until you open the ArrayList class, everything is clear, i got the key point , this is really a nice video
thanks for teach us
please do data structure
love your content
Very nice video. You have a nice way of explaining programming concepts.
Thank you for making this video, it was very helpful and informative! I appreciate it.
Amazing! Easy to understand explanation to generics. Thanks bro.
Great explanation of an important topic. Thanks Bro!
Thx Bro I think you were descend from the sky 😀. We are waiting for more tutorials... Thank you
best channel with best tutorials out there!
I really understand what is arraylist😊
best teacher on youtube❤❤
Nice channel, nice english, nice elocution, nice explaining.
Thanks for making this tutorial. Appreciate it 👍
I liked your end of the session music and fast forward music. What are those?
so helpful thankyou
Phenomenal explanation, thank you
I really like your videos. You explain complex concepts appears easy, thx man
Great
Awesome 👏
Thanks alot
Dam, these videos are gold! So helpful in my bootcamp.
This the guy that taught me how to code fr
Can you create a generic arraylist to hold multiple types, for example: ArrayList newList = new ArrayList(); ??? Thanks for video, explained very well.
This was really helpful for my exams ,Tq broooooooooo
That's so good for the basic bro ! Hope you do more a bout advanced like more complex generic methods. Hope you doing well bro
Great.
Amazing! thanks for this awesome explanation, really appreciate your videos.
Well explained
Thank you for this video.
i am a fellow bro 😎, bro code plaese keep creating videos about java, there are very less content on youtube about java, everyone is posting videos about python , javascript but no one explaining java🥲 , thank you bro.
Wonderful!!
Thanks for the tutorial, Bro.
very good, the best explanetion in the word!!! (i'm from Brazil)
Very good explanation!! Thank u
instantly subbed after that intro :)
yassss! thanks aceman
Loud and clear, on topic, nice animations, your channel is quite underrated
Nice
Fantastic tutorial! Thank you so much :)
this was helpful, exploded my brain, thanks
You are awesome! Thanks for all the help!!
Thanks a lot for this amazing tutorial.
Thanks Bro, this help me to easily understand the basic concept of Generics in Java
Very helpful! Thank you.
Great examples!
Very useful lesson , thank you sir :)))
Nice, thanks
Generic : same method and class but you can use these method and class for any data type instead of one specific data type
Let's Go!!!!! At the end of your Java Playlist!!!!
i swear all the videos 1-3rd comment is best video ever, but which 1 is the best?!
Thank you, it's very helpful.
Thanks
Thankyou so much
Very clear explanation. Thank you Bro. :)
man this video is full of great info , thank you so much !
Great video! Just one question, how can you limit so you can enter only chars and strings?
There doesn't appear to be any easy way to do so since the Character and String classes are in different type hierarchies
@@BroCodez ok thanks, keep up the good work!
Best explanation...
very helpful, thank you
Wow. Magnificent
can we use Object class refer instead of Generic ? are they both the same? if not please explain.
Well, Technically yes we can but there are so many disadvantages when using Object class, But if we use Generics its not complicated as Object. And also Generics is flexible and safe. At the same time, when we are working with Object it requires type-casting which lead us to so many errors.