I'm trying to understand what is happening when I get errors like "groovy.lang.MissingMethodException: No signature of method: Three.method() is applicable for argument types: "
b = "Tea"
class Three
{
String myVar1, myVar2, myVar3, myVar4, myVar5, myVar6
def method(myVar1,myVar2,myVar3,myVar4,myVar5,myVar6)
{
try {
println myVar1, myVar2, myVar3, myVar4, myVar5, myVar6
} catch (groovy.lang.MissingPropertyException e) {
println "error caught"
}
}
}
try {
new Three().method(myVar1:b);
} catch (groovy.lang.MissingPropertyException e) {
println "error caught"
}
try {
new Three().method(myVar1=b);
} catch (groovy.lang.MissingPropertyException e) {
println "error caught"
}
try {
new Three().method(b);
} catch (groovy.lang.MissingPropertyException e) {
println "error caught"
}
I think that you're mixing different concepts... by default groovy classes has two default constructor, the default with no params and the map based constructor which works as follows:
def three = new Three(myVar1:'a',myVar2:'b',myVar3:'c')
println three.myVar1 // prints a
println three.myVar2 // prints b
println three.myVar3 // prints c
However in the case of the methods there isn't this default behavior and due you can not use this kind of invocation and you've to fit the signature of the method, in your case the method expects 6 arguments and you're trying to invoke it passing a map this is why you're getting a missingMethodException
, because there is no method with this signature inside your class.
In your case you only have one method method()
with 6 parameters with not implicit type so you've to invoke it like this:
three.method(1,'kdk','asasd',2323,'rrr',['a','b'])
// or like this
three.method(1,'kdk','asasd',2323,'rrr','b')
// or like this
three.method(1,2,3,4,5,6)
// ...
Note that in your code there is another error, you are invoking println
erroneously inside method()
... use this:
println "$myVar1 $myVar2 $myVar3 $myVar4 $myVar5 $myVar6"
instead of:
println myVar1, myVar2, myVar3, myVar4, myVar5, myVar6
Hope this helps,