Thursday, January 29, 2009

Cool Groovy feature 2

I can't stop surprising by all that cool language features Groovy provides. I like learning them by example. This time it is calling methods asynchronously in Groovy, part two - using Categories. This is not that easy to implement (though it's easy enough) compared to methodMissing approach, however it lacks all that disadvantages of overriding handlers.

Briefly, it uses closures, and functionality provided by use keyword. I guess it could be improved to make the whole thing less verbose, but right now I have no time to think about it. Tried to do something similar in Java using AspectJ, but stuck due to Java syntax limitations due to absence of closures. Using anonymous classes here and there looks ugly and is not less verbose nor easier to understand than straightforward approach.

I wonder if some kind of closures can be implemented in Java using aspects. Haven't found the solution yet.

No comments:

Post a Comment