Advanced Features in Java: Wildcards and Type Capture

Java SE 13    |    Expert
  • 12 Videos | 1h 34m 20s
  • Includes Assessment
  • Earns a Badge
Likes 8 Likes 8
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 course
    recognize how you can constrain type parameters to extend the Comparable and Serializable interfaces
    demonstrate various relationships between base and derived classes in the presence of type parameters
    recognize how type parameters may exist only in the base class, or only in the derived class, or in both
    recognize use-cases where a base class specifies one type parameter and the derived class specifies multiple type parameters
    describe 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 type
    recognize how unbounded wildcards can be used where no information about inheritance relationships is available
    use lower bounded wildcards to specify that a type parameter must be a super-class of a certain type
    recognize scenarios where capture errors might occur and some potential fixes for such capture errors
    analyze compiled bytecode to see how Java uses type erasure to ensure type safety and prevent code bloat
    summarize the key concepts covered in this course

IN THIS COURSE

  • Playable
    1. 
    Course Overview
    2m 54s
    UP NEXT
  • Playable
    2. 
    Comparable and Serializable Type Parameters
    11m 49s
  • Locked
    3. 
    Introduction to Inherited Type Parameters
    10m 1s
  • Locked
    4. 
    Type Parameters in an Inheritance Hierarchy
    9m 56s
  • Locked
    5. 
    Experimentation with Type Parameters in Inheritance
    8m 15s
  • Locked
    6. 
    Introduction to Wildcards
    8m 21s
  • Locked
    7. 
    Upper Bounded Wildcards vs. Bounded Type Parameters
    5m 13s
  • Locked
    8. 
    Unbounded Wildcards
    6m 3s
  • Locked
    9. 
    Lower Bounded Wildcards
    7m 55s
  • Locked
    10. 
    The Capture Error
    6m 54s
  • Locked
    11. 
    Type Erasure
    9m 13s
  • Locked
    12. 
    Course Summary
    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 of this course, which can be shared on any social network or business platform

Digital badges are yours to keep, forever.