简体   繁体   English

Groovy Closure参数名称

[英]Groovy Closure parameters names

I have the following closure: def check = {x,y,z -> some code} 我有以下闭包:def check = {x,y,z - > some code}

Is it possible to get the parameters names("x","y","z") inside the closure? 是否有可能在闭包内获取参数名称(“x”,“y”,“z”)? and to use it as part of the closure code 并将其用作闭包代码的一部分

For example to print arg name and then it's value. 例如,打印arg名称,然后打印它的值。

Thanks 谢谢

You can use of course these parameters in closure. 您当然可以在闭包中使用这些参数。

def a = {a, b, c ->
    a + b + c
}
assert 6 == a(1,2,3)

Second version 第二版

def a = {a, b, c ->
    [a:a, b:b, c:c]
}
assert [a:1, b:2, c:3] == a(1,2,3)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM