how to accept multiple parameters from returning function in groovy

You almost have it. Conceptually [ a, b ] creates a list, and ( a, b ) unwraps 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, which don’t need to be the same type:

final Date foo
final String bar
(foo, bar) = baz()
println foo
println bar

def baz() {
    return [ new Date(0), 'Test' ]
}

Additionally you can combine the declaration and assignment:

final def (Date foo, String bar) = baz()
println foo
println bar

def baz() {
    return [ new Date(0), 'Test' ]
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)