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

Version 1 Next »

Multiple Assignment

Groovy supports multiple assignment, i.e. where multiple variables can be assigned at once, 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.:

Notes:

  • 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:
  • No labels