The map parameter is one of the most commonly used parameter types in the code of the Groovy language, and we often write the following code naturally:
t.testMap(a:1)
t.testMap(a:1,b:1)
t.testMap(a:1,b:1,c:1)
new Person(name:'Tom',sex:23)
These are the uses of the map parameter. And so on, we also often want the list parameter to have the same function, for example, we have the following method with the list object as a parameter:
class Testor2 {
def testList(List list)
{
println list
}
}
We then wrote the following tests:
def t = new Testor2()
t.testList(1,2,3)
We are eager to expect such code to work, unfortunately, the above code will be reported as the following error:
Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: str.Testor2.testList() is applicable for argument types: (java.lang.Integer, java.lang.Integer, java.lang.Integer) values: {1, 2, 3}
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap (ScriptBytecodeAdapter.java:54)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap (ScriptBytecodeAdapter.java:59)
But don't be discouraged, in fact, our array parameters have such a function. For example, we have one of the following methods that takes an array as a parameter:
class Testor2 {
def testArray(int[] arrs)
{
println arrs
}
}
In this way, we can write the following tests:
def t = new Testor2()
t.testArray(1,2,3)
The results of the operation are:
[1, 2, 3]