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?
Java doesn't have named parameters. That's why I said this is "the best Java idiom I've seem for simulating keyword arguments". Objective-C's "named parameters" are also less than ideal, since they force a particular ordering. They aren't true keyword arguments like in Lisp or Python.
Named arguments can improve the readability and safety of your code.
Parameter names identify the local or global parameters that are defined by you or that are specified by the SRC software. The parameter name is a string of alphanumeric characters starting with a letter that does not contain spaces or special characters.
Parameters are the input variables bounded by parentheses when defining a function, whereas arguments are the values assigned to these parameters when passed into a function (or method) during a function call.
Shouldn't the method call be test(a:'1', b:'2');
instead of test([a:'1',b:'2']);
?
Please check Named parameters here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With