Tonight I went to a PittJUG meeting on Closures. Neal Gafter from Google gave a great talk. You could tell he'd done it before and that he really cared about it, and also that he was barely scratching the surface and could talk about this for many more hours. (And that he'd love to do so!)
Some notes from the talk:
Example: implement locking using imported 'withLock' to guard a block of code:
declare: withLock( someLock, someCode ); (not shown, spoken)
usage: withLock( getLock ) {
fee();
fi();
fo();
} <-- look! no semicolon after the block
Closure expressions:
{ [ parameter declarations ] => [block statements] [expression] }
Function types:
{ [ parameter declarations ] => return type [ throws ... ] }
{ String => int throws NumberFormatException}
becomes
java.lang.function.IO<String,NumberFormatException>
^^ I = int, O = Object
or
package java.lang.function;
public interface IO<A, X extends Exception> {
int invoke( A arg ) throws X;
^^^^^^always named invoke (like proxies)
}
Finally:
Homepage of closures proposal: http://www.javac.info/