23 January 2006

Closures for Java

Danny's been talking about Closures in Java. We did a similar thing in JRDF for testing.

AssertThrows.assertThrows(RuntimeException.class, new AssertThrows.Block() {
    public void execute() throws Throwable {
      somethingThatIExpectWillThrowAnException();
    }
});

All in all the syntax is ugly and nowhere near as neat as Ruby's, however such constructs can significantly cut back on duplication.

0 Comments:

Post a Comment

<< Home