Java AdvancedLesson 76Free preview
Java Generics
This lesson is part of Java · All levels
Summary
Generics makes classes, interfaces, and methods work with the newly specified data types when used. The advantage is the safety type and no manual casting is required. Java implements generics through erasure, so type information is deleted from the compiler after the compilation process.
Key points
- Notation <T>; a class may have more than one parameter such as <K, V> on Map
- Generic method written static void
- Bounded type such as <T extends Number> limits the permissible type
- Wildcard:? (all types),? extends T,? super T
- Declarations of generic arrays are immediately prohibited; use ArrayList
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.