While looking through some source code of the open source library groovy-wslite, I came across an annotation I had not seen before - @Delegate. This annotation adds all public instance methods of the annotated field to the present class. In the ...
This one was a lifesaver. I was working on code that processes messages, and needed to add the message id to every log statement. While this sounds straightforward, in reality it wasn't. Here's a very simplified version of the code that illustrate...
Groovy makes it easy to generate xml. Here's an example using MarkupBuilder: import groovy.xml.MarkupBuilder new MarkupBuilder().books { book { name('Groovy in Action, Second Edition') authors { author('Dierk König') author('...
I ran into some issues with groovy constructors today. The real code is rather complicated, so here's a contrived sample that illustrates the issue. Take this very simple groovy class: class Person { String firstName String lastName String ful...