Invoke methods with different arguments in a generic way
<p>Im trying to write a generic code, so that I can <strong>invoke methods at runtime</strong> with different Number &amp; Type of arguments. I have class &amp; different methods at my disposal which I am reading from a file, along with the arguments to be passed into that particular method.</p>

<p>So, here's an Object array which contains values of different type -</p>

<p><strong>Object[] args = new Object[]{"aString", 1, true};</strong></p>

<p>/* based on Object java.lang.reflect.Method.invoke(Object obj, Object... args) , I have written the following method */</p>

<p>//"executingMethod" references the method to be executed, which one can get from Class.forName("ClassName").getDeclaredMethods(); and traversing it for the particular method.</p>

<p><strong>executingMethod.invoke(methodClassObject, args);</strong> //and obviously it doesn't execute because at runtime it doesn't know(can't downcast) param "Type".</p>

<p>I don't want to pass args[0], args[1], args[2] inside executingMethod.invoke(..), as for some case the number of arguments may vary.</p>

<p>Any suggestions pls??</p>
