def
Defines a variable without specifying a type.
Syntax
def name = value
Description
With def, the type is inferred from the value, and the value can change later. You can also explicitly declare the type (int, double, String).
Example
Loading editor…
Expected output
Groovy 20
When to use?
General-purpose variable definition.