Lightweight interfaces instead of function types
Stephen Colebourne
scolebourne at joda.org
Mon Feb 22 05:16:22 PST 2010
On 21 February 2010 18:08, Neal Gafter <neal at gafter.com> wrote:
> On Sun, Feb 21, 2010 at 3:58 AM, Stephen Colebourne wrote:
>> More broadly, it has been noted by more than one person that
>> ClassCastExceptions from ungenerified objects/collections or
>> ArrayStoreExceptions have always been a rarity in real code by
>> comparison to NullPointerExceptions (ie. why aren't we tackling
>> NPEs???).
>
> I'm trying to figure out how this statement fits into the discussion. Are
> you suggesting that because dynamic type safety is hardly ever violated in
> practice, there would be little value in ever reifying generics (compared
> to, for example, the jsr308 work in JDK7 to help eliminate NPEs using
> annotations)? If so, that would explain your eagerness to encourage coding
> patterns that would undermine it.
Were we back pre JDK 1.5, I would be advocating tackling the NPE
problem (and properties) before tackling the CCE problem (generics).
This wouldn't have affected the addition of foreach loops:
Collection coll = new ArrayList();
coll.add("Hello");
for (String str : coll) { ... }
The above does not compile in JDK 1.5/1.6, but it could. It simply
requires the language spec to be a little less "holier than thou".
Doing so would be result in code no less safe than that previously
written in JDK 1.4. (I didn't bother mentioning this in Coin, as I
believe it had 0% chance of being picked).
At this point I see generics as just another verbose problem to work
around in Java, that frequently behaves in apparently weird ways and
often makes me curse out loud. I'm afraid I have no faith that
reification would make matters better.
BTW, I consider JSR-305 annotations to be a nasty hack to the NPE problem.
To answer your question - this affects Lambda's discussion because
this project has to choose a compromise. There is no perfect solution
(do we break arrays, or avoid function types, or only use SAMs,
or...). I'm "helpfully" suggesting that the damage caused by CCE/ASE
has been overstated, relative to NPE, which might affect which
compromise gets chosen.
Stephen
More information about the lambda-dev
mailing list