Exception transparency
Alessio Stalla
alessiostalla at gmail.com
Tue Jun 8 00:15:23 PDT 2010
On Tue, Jun 8, 2010 at 8:38 AM, Neal Gafter <neal at gafter.com> wrote:
> On Mon, Jun 7, 2010 at 11:31 PM, Peter Levart <peter.levart at marand.si>wrote:
>
>> Not introducing disjunctive types as 1st class citizens might be more
>> confusing than introducing them. People might ask why they can catch an
>> exception into a local variable but can't return it's value or assign it to
>> a field. Be prepared for another round of déjà vu: why can't I do new A()
>> where A is a type vaiable...
>>
>
> Because the type A doesn't necessarily have a public no-args constructor.
AND because Java generics do not specify a way to enforce A to have a
public no-args constructor :)
> I suggest a more parallel question would be: why can't I declare a variable
> of type Serializable&Comparable<? super Number>.
>
Yep, this has bitten me a few times. If you have an object of unknown
class which implements several interfaces you find yourself casting
all the time, or assigning the same object to multiple variables. This
happens, for example, with the javax.script.* interfaces ScriptEngine,
Invocable and Compilable when you want to use all of them.
Cheers,
Alessio
More information about the lambda-dev
mailing list