Java Generics Tutorial
Selected Reading
- Java Generics - Discussion
- Java Generics - Useful Resources
- Java Generics - Quick Guide
- Java Generics - No Overload
- Java Generics - No Exception
- Java Generics - No Array
- Java Generics - No instanceOf
- Java Generics - No Cast
- Java Generics - No Static field
- Java Generics - No Instance
- Java Generics - No Primitive Types
- Java Generics - Methods Erasure
- Unbounded Types Erasure
- Java Generics - Bound Types Erasure
- Java Generics - Types Erasure
- Generics - Guidelines for Wildcards
- Lower Bounded Wildcards
- Generics - Unbounded Wildcards
- Upper Bounded Wildcards
- Java Generics - Generic Map
- Java Generics - Generic Set
- Java Generics - Generic List
- Java Generics - Multiple Bounds
- Bounded Type Parameters
- Java Generics - Raw Types
- Java Generics - Parameterized Types
- Java Generics - Multiple Type
- Java Generics - Generic Methods
- Java Generics - Type inference
- Type Parameter Naming Conventions
- Java Generics - Generic Classes
- Java Generics - Environment Setup
- Java Generics - Overview
- Java Generics - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java Generics - No Exception
Java Generics - No Exception
A generic class is not allowed to extend the Throwable class directly or indirectly.
//The generic class Box<T> may not subclass java.lang.Throwable class Box<T> extends Exception {} //The generic class Box<T> may not subclass java.lang.Throwable class Box1<T> extends Throwable {}
A method is not allowed to catch an instance of a type parameter.
pubpc static <T extends Exception, J> void execute(List<J> jobs) { try { for (J job : jobs) {} // compile-time error //Cannot use the type parameter T in a catch block } catch (T e) { // ... } }
Type parameters are allowed in a throws clause.
class Box<T extends Exception> { private int t; pubpc void add(int t) throws T { this.t = t; } pubpc int get() { return t; } }Advertisements