Java 8 Generics in 4 Hours
Published by Pearson
Understand best practices for OO and functional programming
- Learn efficient best practices for using Java’s Generics syntax
- Build a deeper understanding of Java functionality, particularly as it relates to lambdas and streams
- Gain confidence and mastery of Java's Generics to transition to more modern functional style coding
Build a solid understanding of the underlying concepts of Java Generics. Explore why Generics is an essential part of functional programming and how to use it to be a more efficient programmer. This 4-hour course will walk you through the basics and then get you to the point of using more advanced features. Author and trainer Simon Roberts will use real-world programming examples throughout so you can see Generics in action. This course will focus on using Generics for greater reliability, reusability and testability.
What you’ll learn and how you can apply it
By the end of the live online course, you’ll understand:
- co-variance, contra-variance, and invariance, and why a List< Integer > is not a List< Number >
- The value of bounded types
- Limitations of Java's type inference and how to help the system
And you’ll be able to:
- Declare generic types and methods
- Use upper bounded, lower bounded, and unbounded wildcards
- Describe type-erasure and bridge methods and their consequences
This live event is for you because...
- You want to build your mastery of the Java programming language, either as a professional, or as a student
- You want to get the most out of Java's functional features such as lambdas and streams.
- You want to improve your ability to create robust, correct, reusable code.
Prerequisites
- You should be comfortable writing code in the Java programming language and able to read code of intermediate complexity. Superficial familiarity with using generic API classes (such as List) will help but is probably not essential.
Recommended Preparation
- Watch: Functional Programming For Java LiveLessons by Simon Roberts
Recommended Follow-up
- Attend: Modern Java Exception Handling by Simon Roberts
- Watch: Modern Java Collections by Simon Roberts
Schedule
The time frames are only estimates and may vary according to how the class is progressing.
Segment 1: The motivation for Generics in Java (15 minutes)
- Raw types and their problems
- Maintaining backward compatibility
- Adding type information to the compilation process
Segment 2: Limitations of Java's compile-time generics (25 minutes)
- Type is associated with an expression, not with an object
- Non-reifiable types and heap pollution
- Restrictions on
instanceof - Restrictions on overloading
- Invoking the compiler's help
- Restriction on primitive types
Segment 3: Best practices (10 minutes)
- Type inferencing with the diamond operator
- Using
.classand.getClass()for runtime type information - Using
Collectionsfeatures for runtime type checking
Break 10 minutes
Segment 4: Building Generic types (20 minutes)
- Building a simple generic class
- Adding constructors and instance methods to the class
Segment 5: More expressive Generics (30 minutes)
- Adding constraints to generic types
- Meaning of
extendsin generics - Multiple constraints
- Generic capabilities of the
varpseudo-type - Generics with methods, including static methods
Break 10 minutes
Segment 6: Co-variance (50 minutes)
- Understanding the relationship between object-oriented inheritance and generic types
- The frustrations of invariance
- What a co-variant relationship is, when and how to use it, and how to express it in the syntax
Break 10 minutes
Segment 7: Contra-variance (20 minutes)
- What a contra-variant relationship is, when and how to use it, and how to express it in the syntax
Segment 8: Advanced generics, working with arrays and more (25 minutes)
- Mixing arrays with generics
- Building an array from a generic container
- Observing the creation and significance of bridge methods
Course wrap-up and next steps (15 minutes)
Your Instructor
Simon Roberts
Simon Robert's philosophy in training is "understanding is greater than knowledge" meaning simply that although learning facts might be helpful, they can often be looked up. By contrast, it's understanding that allows us to make effective use of those facts, and to extrapolate to new puzzles. Simon is also an FAA certificated flight instructor for Airplane Single Engine and Instrument Airplane, and an avid sailor. He loves to travel and practice speaking French.