I was at a Java conference on Scala the other day and the speaker referred to ‘full powered closures’. I am having a hard time nailing down a definition that makes sense to me. I have read the wiki page on closures but it really didn’t answer it for me. Can someone help me with a clear cut definition? Maybe even include a simple example.
Thanks!
You don’t need more than this sentence from the wikipedia article. What Java lacks (in addition to the ugly syntax) is the feature of binding free variables from outside the closure. An example:
Here the Java compiler will complain about the variable x.
The same thing in scala works just fine and is a lot less verbose: