Named parameters

rdmueller picture rdmueller · Dec 22, 2012 · Viewed 70k times · Source

I have method

def test(String a, String b) { }

and I would like to call this with a dynamic parameter map. I always though that

test(['1','2']); //valid call

and also

test([a:'1',b:'2']); //=> does not work

will work. but it doesn't. So I remembered the spread operator, but can't get it to work....

Is there a way to call a method like the one above with some kind of map as parameter instead of single parameters?

Answer

Tom picture Tom · Dec 22, 2012

Shouldn't the method call be test(a:'1', b:'2'); instead of test([a:'1',b:'2']);?

Please check Named parameters here.