June 2025
Intermediate to advanced
1129 pages
53h
English
In Section 12.2.3, you learned how type erasure makes a construction like class MyException<T> extends Exception impossible. However, a type parameter is permitted in the throws clause. This use opens up interesting options for classes that can throw checked or unchecked exceptions, depending on the use case.
For our next example, the CharIterable interface should be implemented by classes that provide a stream of characters. CharIterable is a generic interface type with a formal type parameter that must later be a subclass of Exception . Consider the following example:
public interface CharIterable <E extends Exception> { boolean ...
Read now
Unlock full access