title: Call a method with arguments by a variable if argument type is unknown
body: <p>I am able invoke a method with arguments by a variable name if number of arguments and argument types are known, But how to get the declared method if no if arguments and argument type are known only at the time of search[search for method ]. </p>
  
  <pre><code>public static void invokeMethod (String myClass, 
                                   String myMethod,  
                                   Class[] params, Object[] args)
                             throws Exception {
     Class c = Class.forName(myClass);
     Method m = c.getDeclaredMethod(myMethod, params);
     Object i = c.newInstance();
     Object r = m.invoke(i, args);
  </code></pre>
  
  <p>}</p>
  
  <pre><code>invokeMethod("myLib", "sampleMethod", new Class[] {String.class, String.class},
         new Object[]
           {new String("Hello"), new String("World")});
  </code></pre>
  
  <p>What if I am not aware of the count and type of <code>Class[]</code>? How to manage this dynamically? I will get the arguments and method through the command line or a socket. So I am not aware that which method will be receiving.</p>
  
  <p>Edit-
  I tried below things-</p>
  
  <pre><code>Class[] css = new Class[10] ;
  Object[] obj = new Object[10];
                  int argLn = params.length;
              if (argLn &gt; 1) {
  
                  func = params[0].trim();
                  for (int Idx = 1; Idx &lt; argLn; ++Idx) {
  
                      arg.add(params[Idx]);
                      try {
                          Integer.parseInt((params[Idx]));
                          css[Idx-1] = String.class;
                      } catch (NumberFormatException ne) {
                          css[Idx-1] = int.class;
  
                      }
                  }
  </code></pre>
  
  <p>But ended up in exception- <code>NoSuchMethodException</code>.</p>