In Groovy Is it possible to passe any parameters to groovy method?
for example:
myMethod(String a)
myMethod(String a, Int b)
myMethod(String a, Int b, date c)
def myMethod (???){
def myHashMap = [:]
//put elements in myHashMap (?)
}
In Groovy Is it possible to passe any parameters to groovy method?
for example:
myMethod(String a)
myMethod(String a, Int b)
myMethod(String a, Int b, date c)
def myMethod (???){
def myHashMap = [:]
//put elements in myHashMap (?)
}
不知道你在问什么,但你可以将任何类型的参数传递给:
def myMethod( ...params ) {
println "Called with : ${params.collect { "$it" }.join( ', ' )}"
}
myMethod( 10 )
myMethod( 'woo', 10 )
您必须按如下方式定义您的方法签名:
def myMethod(String a, Integer b=0, Date c = new Date) // default values for optional params
def myMethod(String a, Integer b=0, Date c = new Date) {
def myHashMap = [:]
...
}