title: Groovy: Dynamic Method Invocation and their parameters
body: <p>Yesterday I started with using Groovy and I found out the <a href="http://groovy.codehaus.org/Dynamic+Groovy" rel="nofollow"> Dynamic Method Invocation </a> function. This is a nice function to call methods dynamically based on their method name.  And this is working fine for me. Now we would like to call these methods based on their name with different parameters. For example I have 2 mehods:</p>
  
  <pre><code> def changeResponseWithParametersAandB(def response, String a, String b) { 
          response.result = args[0];
          return response;
   }
  
   def changeResponseWithParameterA(def response, String a) { 
          response.result = args[0];
          return response;
   }
  </code></pre>
  
  <p>I will loop trough a list with the method names, like:</p>
  
  <pre><code>for (int i = 0; i &lt; methods.size(); i++) {
      DynamicMethods dynamicMethod = methods.get(i);
      methodName = dynamicMethod.getMethodName();
  
      changeFieldValues."$methodName"(response, &lt;HOW_SHOULD_I_DO_THIS_PART&gt;);
  }
  </code></pre>
  
  <p>The only problem is that this won’t work for one of the two methods. I should use for the first method 2 parameters and for the second method 3 parameters. Is there a way to solve this issue in groovy? Or should I just use a map/array or something like that?</p>
  
  <p>Thanks for you answer!</p>