【发布时间】:2017-11-13 13:55:38
【问题描述】:
我在一个用shell.evaluate() 方法加载的groovy 文件中定义了一个闭包。
我需要通过使用shell."$closurename".call(arguments) 调用调用程序来调用这个闭包。
但是,要制定闭包参数(上面的参数),我现在需要知道闭包 $Closurename 接受的参数和参数名称是什么。有没有办法在 Groovy 中动态地知道这一点?我签入了 metaClass.method 属性,但这在下面的示例中不起作用。
下面是示例代码。
def arguments;
shell.evaluate(new File("/tmp/myGroovyClosureFile.groovy"))
testBlock = "myClosureName"
//Code here to find the parameters for myClosureName and create
//the arguments variable
shell."$testBlock".call(arguments)
【问题讨论】:
标签: groovy metaprogramming groovyshell