Parameterized Type and Subtyping

This section describes supertype-subtype relationships with parameterized types derived from generic classes or interfaces.

Parameterized types derived a generic type can also form supertype-subtype relations with other reference types based on following rules:

1. If two generic classes or interfaces have a supertype-subtype relationship, their parameterized types also have supertype-subtype relationships if both are using the same argument type. For example:

   // Generic class declared as
   class LinkedHashSet<E> extends HashSet<E> {}

   // Valid supertype-subtype relation
   // supertype: HashSet<Integer>
   // subtype: LinkedHashSet<Integer>

2. If a generic class or interface is parameterized with 2 different argument types, resulting parameterized types do not a supertype-subtype relationship, even those 2 argument types have a supertype-subtype relationship. For example:

   // Generic class declared as
   class ObjectRegister<E> {}

   // Invalid supertype-subtype relation
   // supertype: ObjectRegister<Number>
   // subtype: ObjectRegister<Integer>

The diagram below shows you some examples of supertype-subtype relationships of parameterized types:
Java Parameterized Type Subtyping

Last update: 2014.

Table of Contents

 About This Book

 Installing JDK 1.8 on Windows

 Execution Process, Entry Point, Input and Output

 Primitive Data Types and Literals

 Bits, Bytes, Bitwise and Shift Operations

 Managing Bit Strings in Byte Arrays

 Reference Data Types and Variables

 StringBuffer - The String Buffer Class

 System Properties and Runtime Object Methods

Generic Classes and Parameterized Types

 What Is a Generic Class?

 Using a Generic Class

 Using a Generic Class - Example

 Creating a Generic Class

 Creating a Generic Class - Example

 Bounded Type Parameters

 Raw Type, Generic Type and Parameterized Type

Parameterized Type and Subtyping

 Wildcard Parameterized Types

 Wildcard Parameterized Type Test

 Wildcard Parameterized Subtyping

 Wildcard Parameterized Subtyping Example

 Generic Methods and Type Inference

 Lambda Expressions and Method References

 Execution Threads and Multi-Threading Java Programs

 ThreadGroup Class and "system" ThreadGroup Tree

 Synchronization Technique and Synchronized Code Blocks

 Deadlock Condition Example Programs

 Garbage Collection and the gc() Method

 Outdated Tutorials


 PDF Printing Version