如何在Groovy中获取方法参数/参数的名称? [英] How to get name of method parameter/argument in groovy?

查看:684
本文介绍了如何在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

这篇关于如何在Groovy中获取方法参数/参数的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆