On Jun 1, 3:50 pm, Moandji Ezana <[email protected]> wrote:
> > So basically, this is just syntax sugar around single-method anonymous inner
> > classes.
>
> Is that such a bad thing? What would, for example, control flow make
> possible that couldn't be done otherwise?

To me, it's not so much a question of good or bad at this point, but
what we're actually getting.  When CICE and BGGA discussions were
happening, things like non-local control flow were explicitly
discussed:
* http://www.javac.info/closures-v05.html
* http://www.javac.info/bloch-closures-controversy.ppt

As a quick realistic example, suppose you want to support resource
closing using a Closeable interface.  With Java 7 syntax, you might
write something akin to this:

public static void withResource(Closeable resource, #() block)
{
  block.();
  resource.close();
}

and somewhere else:

// let's imagine that SQLConnection implements Closeable
SQLConnection conn = ...;
withResource(conn, #() {
  // do stuff
});

Swell, except, it turns out SQLConnection.close() might throw
SQLException.  How do we express that and how does it fit in the flow
of control?  If it was a true closure, the definition of withResource
would not change, because the enclosing block (the code that calls it)
would be able to handle exceptions that come out of the closure.  But
in our current situation, we have to express this notion that
SQLException's implementation of close has to throw some kind of
exception as part of the type of the "closure" (bring on the throws
type variance hell) and subsequently in withResource implementation.
This significantly muddies the waters.

Now, don't get me wrong, I think this will be useful and we'll get
plenty done with it.  But what I'm saying here is that this gives us
very little that we don't already have.  This is just syntax on top of
already existing patterns.  Yes, it'll make code prettier and probably
more readable in most cases, but the boat on the big gains either has
long sailed or was never in the harbor to begin with.

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to