Switching Off Dynamic Typing

All the capabilities of metaprogramming we’ll see in this book rely on Groovy’s dynamic typing, but it comes at a price. Mistakes that would otherwise be found at compile time are pushed to the runtime. In addition, the dynamic method-dispatch mechanism has overhead. Although Java 7 introduced the dynamic invocation feature to ease this performance concern, we’ll still see a performance impact on Groovy running on older versions of the JVM.

We can ask the Groovy compiler to tighten its type-checking from its dynamic relaxed mode to the levels we’d expect from a statically typed compiler like javac. We can also trade in the benefits of dynamic typing and metaprogramming capabilities, and ask the Groovy compiler to ...

Get Programming Groovy 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.