title: Can't invoke method with varargs parameters with reflection - NoSuchMethodException
body: <p>I'm trying to use reflection to invoke method with varargs parameters.</p>
  
  <p>And caught <code>NoSuchMethodException</code>. I couldn't figure out what is wrong here.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>public class ReflectionTest {
  
      public ReflectionTest() {   }
  
      private void varargMethod(String string, Integer ... var) {
  
          System.out.println("vargarMethod() called");
          System.out.println(string + " Number of args: " + var.length
                  + "\nContents");
  
          for (int i = 0; i &lt; var.length; i++) {
              System.out.printf(" args %d: %d", i, var[i]);
              //System.out.println(" args " + i + ": " + var[i]);
          }
  
          System.out.println();
      }
  
      public static void main(String[] args) throws Exception {
  
          Class[] parameterTypes = new Class[] { String.class, int.class, int.class, int.class };
  
          //System.out.println(Arrays.toString(parameterTypes));
  
          Method varMeth = test.getClass().getDeclaredMethod("varargMethod", parameterTypes);
          System.out.println("varMeth" + varMeth);
  
          Object[] arguments = new Object[] { new String("my perfect string"),
                  new Integer(10), new Integer(100), new Integer(47) };
  
          varMeth.invoke(test, arguments);
  </code></pre>
  
  <p>It throws exactly:</p>
  
  <blockquote>
    <p>java.lang.NoSuchMethodException: ReflectionTest.varargMethod(java.lang.String, int, int, int)</p>
  </blockquote>
  
  <ul>
  <li><strong>How to solve this trouble?</strong></li>
  </ul>