3.8 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access