Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Current »

Multiple Assignment

Groovy supports multiple assignment, i.e. where multiple variables can be assigned at once, e.g.:

You can provide types as part of the declaration if you wish, e.g.:

As well as used when declaring variables (as above) it also applies to existing variables, e.g.:

The syntax works for arrays as well as lists, as well as methods that return either of these, e.g.:

Overflow and Underflow

If the left hand side has too many variables, excess ones are filled with null's, e.g.:

If the right hand side has too many variables, the extra ones are ignored, e.g.:


  • currently only simple variables may be the target of multiple assignment expressions, e.g. if you have a person class with firstname and lastname fields, you can't currently do this:
  • currently multiple assignment cannot be used for declaring multiple class fields and initializing them as:
  • No labels