Hacker News new | ask | show | jobs
by Niten 5055 days ago
> 3. You can't do closures in Java. You can. It's just incredibly verbose.

It looks like you're confusing closures with lambda expressions. That's an example of (a more verbose functional equivalent of) a lambda expression, but it isn't a closure.

Java's anonymous inner classes can close over variables in enclosing classes, but they can capture only final variables directly from the enclosing lexical scope. So Java actually does not support true closures.

1 comments

While I agree about the parent confusing closures and anonymous functions, it is possible to use anonymous inner classes as such if the final variable is a single-element array.