Chapter 3Dynamic Typing

In dynamic typing, at runtime types are inferred and methods and their arguments are checked. With this ability, we can inject behavior into classes at runtime, making the code more extensible than with strict static typing.

In this chapter you’ll learn the benefits of dynamic typing and how to use it in Groovy. With dynamic typing, as you’ll see, we can create flexible design with less code than in Java. With the ability to defer arguments’ type verification to runtime, polymorphism in Groovy is on steroids. With the multimethods tool, we can provide alternate behaviors to operations based on the arguments’ runtime types. We’ll cover how to keep these powerful features under control using the static compilation options ...

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.