News for hackers. Stuff that matters.
Re:Streams in Java 8 by javafu2 on Sunday February 09, 2014 @06:52PM (#7208083)
You can not modified a variable declared in the outer scope inside a lambda.

int a = 0; list.forEach(element -> { a++; // no way ! });

That's why it's a lambda and not a closure BTW.

Re:Streams in Java 8 by mbell on Sunday February 09, 2014 @07:00PM (#7208118)
It's still a closure, just a closure with immutable capture, just like Python. Also like Python, you can get around it by boxing the variable you would like to modify (or using nonlocal in Python 3).

IMO the lack of exception transparency is going to be more of an issue with Java's lambdas.

Re:Streams in Java 8 by javafu2 on Sunday February 09, 2014 @07:43PM (#7208338)
For most of the used programming languages, a lambda captures values (like in Java or Python), and closure capture variables or scope (like in Scheme or Ruby), hence the name, a closure close (bind) the free variable of the closure to the ones of the lexical scope.

The lack of checked exception transparency is for me something that goes in the right direction. The hidden message is 'Use checked exception only for IOs and please don't create your own exceptions, use already existing ones !'

Re:Streams in Java 8 by mbell on Sunday February 09, 2014 @08:08PM (#7208443)
A lambda doesn't capture anything, it's just an anonymous function. A lambda can be a closure, but it doesn't have to be.

Closures come in two primary flavors, bind by value or bind by reference. Some languages implement only one of these, some implement both, some bind in completely different ways (e.g. lazy binding in Haskell).

Re:Streams in Java 8 by AYBABTME on Monday February 10, 2014 @02:10AM (#7209588)
Can always make:

   final int[] a = {0};
   list.forEach(element -> { a[0]++; });