title: Java reflection: automatically invoke the right overloaded method based on parameters and signature
body: <p>Say have an overloaded method called <code>doTask</code>:</p>
  
  <pre><code>public class Game {
    void doTask(Joker joker);
    void doTask(Batman batman, Robin robin);
  }
  </code></pre>
  
  <p>I would like to invoke the right method, given the name of the method (<code>"doTask"</code>) and an array of parameters whose number and types are not known a priori.</p>
  
  <p>Normally, this involves three steps at least:<br>
  1. Find the number of the parameters and their types, and make an array <code>Class[] myTypes</code>.<br>
  2. Identify the correct overloaded <code>Method</code>, i.e. <code>Method rightMethod = game.getClass().getMethod("doTask", myTypes);</code><br>
  3. Invoke the method: <code>rightMethod.invoke(paramArray)</code>.</p>
  
  <p>Does there exist a facility to ask Java reflection to automatically identify the right overloaded method to use, and save us from having to do Steps 1 and 2? I'm thinking ideally, this would be like:<br>
  <code>Library.invoke("doTask", paramArray);</code></p>