> @NamedVariant
> def foo(a, @NamedParam String b, c, @NamedParam(required=true) d) {
> println "$a $b $c $d"
> }
>
> which produces a method like this:
>
> def foo(Map _it, a, c) {
> assert _it.containsKey('d')
> this(a, _it.b, c, _it.d)
> }
Do you mean there will be additional method while original method will be left
as is?
In case of named parameter with default value, there will be tree methods:
def foo(a, @NamedParam b = 42, @NamedParam c) { a+b+c } // source method
def foo(Map _it, a) { this(a, _it.b, _it.c) } // generated from @NamedParam
def foo(a, c) { this(a, 42, c) } // generated from default value
def foo(a, b, c) { a+b+c } // actual method
Will default be passed if I invoke code with foo(“value for a”, c: 13) ?
How ‘required’ is supposed to work with default parameters?
Why not leverage default params instead of introducing ‘required’? I.e. all
named params are required by default.
—
Daniil Ovchinnikov
Software Developer
JetBrains
jetbrains.com
“Drive to develop”