jastrachan | 23 Feb 08:38 2005
Picon

Re: Problem with invokeMethod

Note that in Groovy you don't have to use the invokeMethod() mechanism. 
You can call it directly...

n 22 Feb 2005, at 20:47, Claudio Raul Sanchez wrote:
> Hello, I've a problem using groovy embedding in java.
> I have java class with two methods: methodTest() and 
> methodTest(boolean test)
>  Using groovy I try to execute the method without parameters and the 
> the method with parameter but I realize that groovy allways execute 
> the method "methodTest" without parameters.
>
>  This a bug or I need to do something else for groovy execute the 
> correct method?
>
> For example when I execute the following code, groovy allways excute 
> methodTest() instead methodTest() first and then methodTest(false)
>
>         public static void main(String[] args) throws Exception {
>                  BusinessBeanImpl businessBean = new 
> BusinessBeanImpl();
>
>                 String groovyExpWithOutParam = "println obj 
> ;obj.invokeMethod('methodTest',[])";
>                
>                  String groovyWithParam = "println obj 
> ;obj.invokeMethod('methodTest',[false])";

                String groovyExpWithOutParam = "println obj 
;obj.methodTest()"               
                  String groovyWithParam = "println obj 
;obj.methodTest(false)";

Should fix it.

I think the reason for the strange behaviour is because you are passing 
in an empty list expression ([]) to the method call rather than null, 
which the runtime might coerce to a boolean?

James
-------
http://radio.weblogs.com/0112098/


Gmane