
Discover the power of Java generics, from parameterized types and auto boxing to unboxing, creating custom generic classes, wildcards, bounds, and their impact on inheritance.
Understand how generics improve Java array lists by replacing raw object storage with type-specific lists, avoiding casts and class cast exceptions when retrieving elements.
See how generics enforce type safety in lists by restricting to strings, preventing unsafe casts, and enabling compiler checks, with auto boxing for primitive types.
Understand autoboxing and unboxing in Java, and how wrapper classes enable generics to use primitives in lists and other collections.
Explore parameterized types and generics in Java by inspecting lists, type parameters like E, and how return values and iterators adapt to the declared type.
Explore how Java generics are a compile-time construct with type erasure at runtime, safeguarding type checks while making lists of strings behave like other lists.
Compare generics as a compile-time construct with runtime arrays, showing how generic lists are type-checked at compile time while arrays enforce types at runtime.
Learn how to design a generic Java class, a cage, that stores two animals of the same type using generics, providing compile-time type safety and scalable reuse for future classes.
Explore how generics interact with constructors in Java, showing why and how to declare a generic constructor, handle type parameters, and ensure correct type assignment between raw and parameterized types.
Explore how inheritance and polymorphism work with Java generics, and why a list of strings cannot be assigned to a list of objects due to type safety.
Explore generics wildcards in Java, learn how the question mark denotes an unknown type, when to read from a wildcard list, and why you can't add elements to such lists.
Explore Java generics with upper bound wildcards using extends to constrain lists to numbers, enabling safe operations on integers or doubles and clarifying type checks.
Explore generics wildcards by constraining a cage to hold only animals, using an Animal base type with Lion and Monkey subclasses and an upper-bounded wildcard.
Learn how Java generics support multiple type parameters, using maps to show distinct key and value types, and declare them with comma separated types in angle brackets.
Explore Java generics with multiple upper bounds, using the ampersand to require a type to extend a class and implement interfaces like eat and runs, and learn syntax and ordering.
Explain lower bound wild card in Java generics and how to write to a list, using super and producer extends consumer super (SPDC) to handle numbers and read/write constraints.
Explore how static methods work with generics in a zoo cage example. Define a static isCompatible method with its own type parameter and wildcards, then call it without an instance.
Summarize core generics concepts in Java, including type safety, auto boxing and unboxing, parameterized and custom generic types, and wild cards with upper and lower bounds.
How often do you use Java Generics when writing your own types?
Java Generics is very much an underrated and underutilized feature of Java. Yes, Java Generics is a necessary skill when working with Collection classes. But the true power lies with using it for your own types!
Most Java developers get by with a rudimentary knowledge of Generics. However a good understanding of Generics adds an extra dimension to your Java code that makes it more type-safe and easier to work with.
This course covers an in-depth treatment to Java Generics and turn it from being a pain to being a joy to use.
Topics covered:
- Learn how Generics works with primitive types in conjunction with another Java feature - autoboxing and unboxing
- Understand what parameterized types are. What does it mean to add parameter to type information?
- Learn how to create your own custom generic types
- Implications of Generics with inheritance and polymorphism
- Understand wildcards, upper bounds and lower bounds with Generics
- Learn how to work with static methods using Generic types
Taught in the inimitable Java Brains style, this course covers everything you need to know to wield the power of Generics in your Java code as well as understand Generics syntax in other Java code.