Java Tutorials - Herong's Tutorial Examples - Version 7.03, by Dr. Herong Yang
What Is a Generic Class?
This section describes what is a generic class, a class that supports one or more type parameters. When a specific type value is given, a generic class becomes a normal 'specific' class.
What Is a Generic Class? A generic class is a class that supports one or more type parameters. When invoked with a given type argument, a generic class becomes a parameterized class.
A generic class uses a type parameter to make it more generic so that it can be used as multiple variations, one variation for each specific type given to the type parameter.
For example, java.util.Stack<E> is a generic class. It supports a single type parameter E. java.util.Stack<E> can be viewed as multiple classes when used with E parameterized to different reference types. Each of them is a variation of java.util.Stack<E>:
When a generic class is used with a given specific type, Behaviors of its methods will change accordingly.
For example, if java.util.Stack<Integer> is used, its method "public E push(E item)" will become "public Integer push(Integer item)".
Last update: 2014.
Table of Contents
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
Using a Generic Class - Example
Creating a Generic Class - Example
Raw Type, Generic Type and Parameterized Type
Parameterized Type and Subtyping
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