I have been a Groovy user for a long time. I have dabbled a bit with Scala, being lured by the promise of static type checking. Being a huge fan of static type checking I tried to love Scala (even just like it), but I always ended up back in Groovy because it is more productive for me.

So, with the recent announcement of the Groovy 2.0 release, I hoped that the new TypeChecked annotation would be the silver bullet I had been waiting for. Alas, I have found that, although the TypeChecked annotation does indeed turn on static type checking, it does not translate to the real world if you are using closures (which you would if programming in Groovy).

Below is a snippet of code, which you would expect on quick inspection to not compile. This is because the code is attempting to iterate of a list of String objects and treat them as Integer objects.

static void example(List<String> args) {
   args.each { Integer it -> println it }

In fact this code will compile, but will fail when executed with a run-time error (since you cannot cast a String to an Integer).

The reason is that the each() method signature takes a Closure which is untyped. As such, the Groovy compiler is unable to detect that the Closure is expecting objects of the type that are contained in the list being iterated over.

Overall, I am still very bullish over the adoption of Groovy 2.0 in the enterprise.