Generic Classes and Parameterized Types
This chapter provides tutorial notes and example codes on generic classes and parameterized types. Topics include what is a generic class; what is a type parameter; using parameterized types and subtyping; using wildcard parameterized types and subtyping.
These sections are omitted from this Web preview version. To view the full content,
see information on how to obtain the full version this book.
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
- A generic class is a class that supports type parameters with different behaviors when given different types on invocation.
- A generic class has a signature of ClassName<A, B, C, ...>.
- Type parameters can be bounded as ClassName<T extends C & I1 & I2...> to ensure strong typing to reduce runtime type mismatches.
- A parameterized type is a reference type for generic class objects with argument types provided.
- Subtyping of parameterized types is based on their generic class hierarchy, like class Hashtable<K,V> extends Dictionary<K,V>.
- Raw types for generic types introduced in JDK 1.5 are supported for backward compatibility.
- A wildcard parameterized type is a parameterized type with argument types containing wildcards for subtyping purposes.
- There 3 categories of wildcard parameterized types: unbounded, upper bounded and lower bounded.
Table of Contents
About This Book
JDK - Java Development Kit
Execution Process, Entry Point, Input and Output
Primitive Data Types and Literals
Control Flow Statements
Bits, Bytes, Bitwise and Shift Operations
Managing Bit Strings in Byte Arrays
Reference Data Types and Variables
Enum Types and Enum Constants
StringBuffer - The String Buffer Class
System Properties and Runtime Object Methods
►Generic Classes and Parameterized Types
Generic Methods and Type Inference
Lambda Expressions and Method References
Java Modules - Java Package Aggregation
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
Assert Statements and -ea" Option
Annotation Statements and Declarations
Java Related Terminologies
Full Version in PDF/EPUB