View RSS Feed

Advanced Java

Advanced Java programming.

  1. Generics - Exceptions

    by , 11-29-2011 at 03:35 AM
    Due to erasure, exception use is limited with generics. As exceptions are know at both compile and at run time, it renders redundant the use of catch clauses. This also means that a generic class cannot inherit directly or indirectly from Throwable.

    One can though use type parameters in the throws clause of a method declaration. This will allow you to write generic code that varies with the type of a checked exception:

    Java Code:
    import java.util.List;
    
    public interface
    ...