Exception transparency
Brian Goetz
brian.goetz at oracle.com
Tue Jun 8 05:28:58 PDT 2010
The problem has nothing to do with syntax; the problem has to do with the
compiler incorrectly assuming a type parameter is variadic. In the latter
case "implements List<T>" would not compile!
On 6/8/2010 1:26 AM, "Zdeněk Troníček" wrote:
>
> 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.
More information about the lambda-dev
mailing list