JavaFX2 and GWT are exceptions to the rule, the vast majority of Java 
APIs/frameworks are not designed to benefit from intense use "closures" even 
in cases where such intense use would usually be a no-brainer design - 
remarkably collections (where are methods like collect, select, foreach 
etc.) - this alone is enough evidence that Java does not have decent closure 
support.

Notice that both JavaFX2 and some other very recent APIs (e.g. for 
concurrency) were/are being explicitly designed with Java 8's lambdas in 
mind. The master plan is that right now we need that horrendous code with 
inner classes, but RSN we'll be using the same frameworks with lambdas and 
THEN these frameworks will be used they way they were designed to be used. 
(But that way will not yet be as powerful as in languages with full 
closures.)

Finally, let's propose a pact, shall we?

1) Everybody agrees that (a) inner classes are functionally equivalent to 
Java 8's lambdas, and (b) both are compatible with a "pragmatic" definition 
of closures;
2) Everybody agrees that this form of closures that we have above, has the 
defect of not being orthogonal with the rest of the language. Mutability is 
an extremely fundamental aspect of Java; I too, like to write side-effect 
free code in Java (see my article in NetBeans Magazine Issue 1...), but this 
is a programmer idiom that has zero support from the language. And we cannot 
claim Java to be some sort of functional-hybrid language or to contain a 
functional subset; the closure-specific restriction to mutable capture is 
pathetically too-little to qualify for that.

A+
Osvaldo

On Monday, September 12, 2011 11:16:59 PM UTC-4, clay wrote:
>
> People don't use closures in Java that much? I emphatically disagree. 
> I completed writing a JavaFX 2 application in Java: Every single 
> button handler or GUI event handler uses an anonymous class wrapped 
> around a function, and most of those access local or instance 
> variables from the defining scope, where my coworkers and I refer to 
> it as a closure. The Swing and GWT APIs are also designed for heavy 
> use of anonymous functions and closures (most Java server side web 
> frameworks don't use anonymous functions at all). We also do the same 
> thing in our (non Java) JavaScript client code and we call them 
> closures there as well. 
>
> No, I'm really not being pedantic. I use closures so extensively in 
> Java, it is ridiculous to say that they don't exist. That's like 
> telling me Java doesn't have a for loop or exceptions. 
>
> On Sep 12, 8:47 pm, phil swenson <[email protected]> wrote: 
> > http://en.wikipedia.org/wiki/Pedantic 
> > 
> > Java doesn't have closures in the way most people think of closures. 
> > It has closures in a half-assed, un-friendly way.  So people don't use 
> > them much and in effect, Java doesn't have closures.

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/javaposse/-/lZOF2RAH4goJ.
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