如何将任意参数传递给包装的groovy函数?

时间:2019-10-17 20:03:21

标签: groovy wrapper keyword-argument

我有一个普通的包装函数,我想将任意参数传递给包装的方法调用。

示例:

// Arguments: appliance, temperature, duration
def cook(Map args = [:]) {
    print(args.appliance)
    print(args.temperature)
    print(args.duration)
}

// Arguments: appliance, plus whatever arguments cook() has
def cookWithKitchenAid(Map cookArgs = [:]) {
    cook(appliance: "KitchenAid " + cookArgs.appliance, cookArgs)
}

cookWithKitchenAid(appliance: "oven", temperature: "300", duration: "60")

Python有一种传递任意关键字参数的方式,请参见https://stackoverflow.com/a/36611057/1698736。 groovy等于什么?

0 个答案:

没有答案