3.5 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 ...
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