DevOps / Apache Groovy Interview questions
How does Groovy support optional typing?
Groovy lets you declare variables, parameters, and return types either explicitly (String name) or dynamically with def, mixing both styles freely within the same codebase or even the same method.
Without an explicit type or def-driven static checking, Groovy resolves method calls dynamically at runtime based on the object's actual type at that moment, rather than checking against a declared type at compile time.
Annotations like @TypeChecked and @CompileStatic let you opt specific classes or methods into stricter, Java-like compile-time type checking, so optional typing isn't all-or-nothing across an entire codebase - it can be applied selectively where it adds the most value.
More Related questions...