In groovy, for a method to accept named parameters, its first argument must
be a map.

All named parameters are assigned to that map, and the rest of the
parameters will be the other parameters in the order that you passed them.

In your example, as your method does nos specify types, the first parameter
is a map with all your named parameters, and then you have arg1 with the
first non-named parameter, and args with the remaining parameters.

You can see a nice example and explanation here.
http://mrhaki.blogspot.com.ar/2009/09/groovy-goodness-named-parameters-are.html

At least, that is my understanding about named parameters :-)

On Sun, Apr 5, 2015 at 12:06 PM, roro codeath <[email protected]> wrote:

>
> ---------- Forwarded message ----------
> From: roro codeath <[email protected]>
> Date: Sun, Apr 5, 2015 at 10:58 PM
> Subject: Why arguments are inversed when i use meth(arg, arg2, ...args
> To: [email protected]
>
>
> see my example:
>
> class Ex3 {
>     def m(arg, arg2, ... args) {
>         println "arg: $arg"
>         println "arg2: $arg2"
>         println "args: $args"
>     }
>
>     static void main(args) {
>         new Ex3().m(1, 2, k: 'v')
>     }
> }
>
>
> I get output
>
> arg: [k:v]
> arg2: 1
> args: [2]
>
>
> but i expect
>
> arg: 1
>
> arg2: 2
>
> args: [k:'v']
>
>
> my gradle version is:
>
> ------------------------------------------------------------
> Gradle 2.3
> ------------------------------------------------------------
>
> Build time:   2015-02-16 05:09:33 UTC
> Build number: none
> Revision:     586be72bf6e3df1ee7676d1f2a3afd9157341274
>
> Groovy:       2.3.9
> Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
> JVM:          1.8.0_05 (Oracle Corporation 25.5-b02)
> OS:           Linux 3.13.0-24-generic amd64
>
>
>

Reply via email to