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.:
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:
person class with firstname and lastname fields, you can't currently do this: