Optional Typing

Groovy is dynamically typed and optionally typed; we can adjust the dial of typing all the way to one extreme, where we do not specify any type and let Groovy figure things out, or we can move the dial all the way to the other extreme, where we will precisely specify the types of variables or references we use.

Remember that Groovy is a language that runs on top of the JVM. Optional typing can help integrate Groovy code with Java libraries, frameworks, and tools. Sometimes Groovy’s dynamic type-mapping doesn’t match what these libraries, frameworks, or tools expect. Such a situation is not a showstopper in Groovy—we can switch the typing mode readily and specify the type information to get moving. Optional typing is useful ...

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.