Folks, I mentioned this earlier, but no one seemed to pick up on it. The one real difference between closures and constructs like Java's SAM's or anonymous functions is how control flow is treated. Not just in trivial cases like branching and looping, but think about continuations, exception propagation, etc. This is where Java comes up short if you wanna do those things. My understanding is that Java 8 syntax doesn't address this, so we're still stuck using whatever we had before, but with cleaner, nicer presentation (syntax). Again, not something I consider a deal breaker, but an important factor nonetheless.
Alexey ________________________________ From: clay <[email protected]> To: The Java Posse <[email protected]> Sent: Tuesday, September 13, 2011 2:15 PM Subject: [The Java Posse] Re: Java Has Always Had Closures Regarding "pass by reference", most people will say Java passes objects by reference, when it is more accurate to say that they pass object references by value. I don't think there is much confusion or debate on that issue. With Closures, there is a lot of confusion. Java has something extremely close to closures, and only a real pedant can debate the distinction. I also think when people say that Java lacks closures, they are referring to first class functions and concise anonymous function syntax instead. "What you are describing, though, sounds like you really should jump ship to one of the alternative languages." That's actually a different issue: which language is a better fit for a project. And I don't disagree, for functional programming support, clearly Java is behind the pack. For this thread, I just wanted to clarify what a closure is, and what people really mean when they say that is missing from Java. For your loop example, can't you simply do: for (int x = 0; x < count; x++ ) { final int x2 = x; new Runnable() { public void run() {someFunctionOn(x2);}}.run(); } or for (int x = 0; x < count; x++ ) { someFunctionOn(x); } -- 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. -- 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.
