如何在Groovy中获取方法参数/参数的名称?

问题描述:

我有一个groovy脚本,该脚本具有一个带有2个参数的函数,其中一个是hashmap.我想检查一个函数内部是否包含一个子字符串的hashmap变量的名称.我该怎么办?

I have groovy script that has a function with 2 arguments, one of which is a hashmap. I want to check the name of a hashmap variable contains a substring or not, inside a function. How do i do it?

def myfunc(String var, HashMap var2)
{
    // need a routine to retrive the name of the variable var2
} 

在这里已作了很好的解释: 获取方法参数的名称

It's well explained here : Getting the name of a method parameter

要访问groovy脚本的方法,请遵循以下语法:

To access groovy script's method follow syntax :

metaClass.methods