Generics and Inheritance: Notes
Generics and Inheritance Notes
Generics can be used with inheritance in several ways:
- A generic class can be derived from a non-generic class. For example, the Object class is a direct or indirect superclass of every generic class.
- A generic class can be derived from another generic class. For example, generic class Stack (in package java.util) is a subclass of generic class Vector (in package java.util). We discuss these classes in Chapter 19, Collections.
- A non-generic class can be derived from a generic class. For example, non-generic class Properties (in package java.util) is a subclass of generic class Hashtable (in package java.util). We also discuss these classes in Chapter 19.
- Finally, a generic method in a subclass can override a generic method in a superclass if both methods have the same signatures.