Java Generics
Java Generics enable us to gain type safety in situations where classes and methods that are designed to be able to work with any type would otherwise be designed to work with Object instances. For instance, without Java Generics the Java List, Java Set, Java Map etc. interfaces would all be working on Object instances. With Java Generics you can create List, Set or Map instances that work on specific types, e.g. a List of Strings, rather than a List of Objects, so you achieve a higher type safety in your code.
Java Generics add type parameters to classes, interfaces, methods and variables that decide to use them. To be able to use a type parameter with a class, interface, method or variable the type you are trying to add the type parameter to, must be designed to allow generic type parameters.
Many of Java's built-in utility classes and interfaces are designed to allow generic type parameters. This Java Generics tutorial shows examples of how to use generic type parameters with some of these classes. Once you have seen a few examples, you can figure out how to use generic type parameters in general.
You can also design your own classes, interfaces and methods to use usable with Java Generics - meaning enabling them to take type parameters. This Java Generics tutorial also shows how to do that.
Chapters:
0:00 Java Generics Introduction
0:24 Java Generics Example
8:32 Java For Each Loop Using Generics
9:37 Java Collections Support Generics
11:19 Java Generics in Your Own Classes (Method Level)
14:57 Java Generics in Your Own Classes (Class Level)
20:47 Java Generics in Your Own Classes (Field Level)
24:20 Class Objects as Generic Type Literals
28:15 Java Generics in Your Own Interfaces
34:39 Java Generic Wildcards
36:50 Java Generic Wildcards ?
40:59 Java Generic Wildcards ? extends SomeClass
44:57 Java Generic Wildcards ? super SomeClass
X (Twitter): @jjenkov
LinkedIn: https://www.linkedin.com/in/jakob-jenkov-4a3a8/
Java Generic Tutorial - text:
https://jenkov.com/tutorials/java-generics/index.html
-
LIVE
The Quartering
2 hours agoTim Pool GOES BALLISTIC & QUITS Timcast IRL, Blasts Entire Staff, Kamala Harris BUSTED & More
5,521 watching -
2:11:14
Pro League Network
22 hours agoPutt Tour (Pro Minigolf 10.21.24)
972 -
LIVE
SwitzerlandPlayIT
3 hours agoDitching CnC3 for Wolfenstein!!!
489 watching -
8:23
Howard Lutnick
1 hour agoHoward Lutnick on Fox Business with Larry Kudlow
3.05K1 -
LIVE
Sm0k3m
2 hours agoPlaying games on Rumble
734 watching -
LIVE
Akademiks
2 hours agoDiddy Snitching on Other CEOs?? Catches 5 New Lawsuits. Kendrick Lamar discusses Not Like Us.
4,536 watching -
27:19
Russell Brand
3 hours agoSHOCKING New Pfizer Lies EXPOSED! FDA KNEW Vaccine Risks And Hid It! SF474
81.4K247 -
1:33:28
vivafrei
3 hours agoLaura Loomer SUING Bill Maher? Democrat Desperation & Hypocrisy!
41K20 -
30:53
The Boomer Effect
16 hours agoThe Disappearance of the American Farmer
11.4K -
1:17:58
TheAlecLaceShow
3 hours agoGuests: Rep. Jim Jordan & Dr. Robert Malone | McDonald Trump | 2 Weeks To Go | The Alec Lace Show
16.9K4