Exception transparency

"Zdeněk Troníček" tronicek at fit.cvut.cz
Mon Jun 7 22:26:13 PDT 2010


Brian Goetz napsal(a):
>> I conjecture that a new syntax may not be needed at the declaration site
>> at all; it can be inferred from the explicit bound on the type parameter
>> instead of vice-versa, simplifying the syntax and making it more
>> familiar.  Specifically, you can treat any type parameter as a throws
>> type parameter if its bound is Throwable or a subtype.  There is no need
>> to restrict where the type parameter may be used.
>
> I suspect we might regret that.  When you try to write a class like
>    class ExceptionList<T extends Exception> implements List<T> { ... }
> you'll find that the compiler has guessed your intentions incorrectly.
>

Could you elaborate on what is wrong with the following code in your opinion?

class ExceptionList<T extends Exception> implements List<T> {

    ExceptionList() throws T { ... }
    ...
}

In comparison to

class ExceptionList<T extends Exception, throws E> implements List<T> {

    ExceptionList() throws E { ... }
    ...
}

the former syntax does not seem to be worse.

Z.
-- 
Zdenek Tronicek
FIT CTU in Prague



More information about the lambda-dev mailing list