You almost have it. Conceptually, [ a, b ] creates a list, and ( a, b ) expands one, so you want (a,b)=f1(a) instead of [a,b]=f1(a) .
int a=10 int b=0 println "a is ${a} , b is ${b}" (a,b)=f1(a) println "a is NOW ${a} , b is NOW ${b}" def f1(int x) { return [x*10,x*20] }
Another example returning objects that should not be of the same type:
final Date foo final String bar (foo, bar) = baz() println foo println bar def baz() { return [ new Date(0), 'Test' ] }
In addition, you can combine the declaration and purpose:
final def (Date foo, String bar) = baz() println foo println bar def baz() { return [ new Date(0), 'Test' ] }
Justin Piper Jul 20 2018-11-11T00: 00Z
source share