Advanced Features in Java: Wildcards and Type Capture
Java
| Expert
- 12 videos | 1h 29m 20s
- Includes Assessment
- Earns a Badge
In this course, you'll explore how wildcards and type capture work, as well as how type erasure manifests itself in compiled bytecode. You'll start by examining how the wildcard operator, represented in syntax by the ? character, can be used in situations where you don't know up-front what type argument to specify for a particular type parameter. Next, you'll learn the three types of wildcard type parameters. Unbounded wildcards, where you know nothing at all about the type; upper bounded wildcards, which define type parameters that must inherit from a specific base class or interface; and finally lower bounded wildcards, which can be used to specify constraints in the other direction - namely that the type must be a super-class of a specified type. Next, you'll see that capture errors occur when Java is unable to infer the correct type to pencil in as the type argument for a given type parameter. Finally, you'll examine bytecode to see that whenever you create a class or method with a type parameter, Java creates just one single copy of such code, and pencils in a type parameter of java.lang.Object. It also adds various type checks to ensure that the code is used correctly. This is known as type erasure and forms the basis of the great performance of Java generics.
WHAT YOU WILL LEARN
-
Discover the key concepts covered in this courseRecognize how you can constrain type parameters to extend the comparable and serializable interfacesDemonstrate various relationships between base and derived classes in the presence of type parametersRecognize how type parameters may exist only in the base class, or only in the derived class, or in bothRecognize use-cases where a base class specifies one type parameter and the derived class specifies multiple type parametersDescribe how wildcards mitigate some limitations of invoking methods with generic input arguments
-
Use upper bounded wildcards to specify that a type parameter must be a sub-class of a certain typeRecognize how unbounded wildcards can be used where no information about inheritance relationships is availableUse lower bounded wildcards to specify that a type parameter must be a super-class of a certain typeRecognize scenarios where capture errors might occur and some potential fixes for such capture errorsAnalyze compiled bytecode to see how java uses type erasure to ensure type safety and prevent code bloatSummarize the key concepts covered in this course
IN THIS COURSE
-
2m 54s
-
11m 49sUpon completion of this video, you will be able to recognize how you can constrain type parameters to extend the Comparable and Serializable interfaces. FREE ACCESS
-
10m 1sLearn how to apply various relationships between base and derived classes in the presence of type parameters. FREE ACCESS
-
9m 56sUpon completion of this video, you will be able to recognize how type parameters may exist only in the base class, or only in the derived class, or in both. FREE ACCESS
-
8m 15sUpon completion of this video, you will be able to recognize use-cases where a base class specifies one type parameter and the derived class specifies multiple type parameters. FREE ACCESS
-
8m 21sUpon completion of this video, you will be able to describe how wildcards mitigate some limitations of invoking methods with generic input arguments. FREE ACCESS
-
5m 13sFind out how to use upper bounded wildcards to specify that a type parameter must be a subclass of a certain type. FREE ACCESS
-
6m 3sUpon completion of this video, you will be able to recognize how unbounded wildcards can be used where no information about inheritance relationships is available. FREE ACCESS
-
7m 55sFind out how to use lower bounded wildcards to specify that a type parameter must be a superclass of a certain type. FREE ACCESS
-
6m 54sAfter completing this video, you will be able to recognize scenarios where capture errors might occur and some potential fixes for such capture errors. FREE ACCESS
-
9m 13sIn this video, you will analyze compiled bytecode to see how Java uses type erasure to ensure type safety and prevent code bloat. FREE ACCESS
-
2m 46s
EARN A DIGITAL BADGE WHEN YOU COMPLETE THIS COURSE
Skillsoft is providing you the opportunity to earn a digital badge upon successful completion on some of our courses, which can be shared on any social network or business platform.
Digital badges are yours to keep, forever.