title: Reflections IllegalArgumentException causes
body: <p><strong>UPDATE</strong> - To make the question clearer.</p>
  
  <p>What is the possible cause of getting a ClassCastException while calling a method via reflections?</p>
  
  <p>I got the following stacktrace as a part of my application while trying to invoke a method via reflections.</p>
  
  <pre><code>java.lang.IllegalArgumentException: java.lang.ClassCastException@21fea1fv
      at sun.reflect.GeneratedMethodAccessor332.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at com..... 
      (remaining is my method stack trace)
  </code></pre>
  
  <p>I tried an example class and passed various arguments of different types to it, but i always get a this exception.</p>
  
  <pre><code>java.lang.IllegalArgumentException: argument type mismatch
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  </code></pre>
  
  <p><strong>UPDATE -</strong> 
  Here is the sample code i wrote to try recreating the exception</p>
  
  <p>Interface to create proxy class</p>
  
  <pre><code>package my.tests;
  
  public interface ReflectionsInterface { 
      public abstract void doSomething();
  }
  </code></pre>
  
  <p>This is the test class</p>
  
  <pre><code>package my.tests;
  
  import java.lang.reflect.InvocationHandler;
  import java.lang.reflect.Method;
  import java.lang.reflect.Proxy;
  
  public class Reflections implements ReflectionsInterface {
  
      public static void main(String[] args) {
          Reflections reflections = new Reflections();
          ReflectionsInterface reflectionsProxy = reflections.createProxy(ReflectionsInterface.class);
          invokeMethod(reflectionsProxy, "doSomething", null);
      }
  
      public &lt;T&gt; T createProxy(Class&lt;T&gt; entityInterface) {
          EntityInvocationHandler eih = new EntityInvocationHandler(this);
          T cast = entityInterface.cast(Proxy.newProxyInstance(
                  entityInterface.getClassLoader(), new Class[]{entityInterface}, eih));
          return cast;
      }
  
      public static void invokeMethod(Object obj, String methodName, Object... args) {
          Method[] methods = obj.getClass().getMethods();
          try {
              for (Method method : methods) {
                  if (method.getName().equals(methodName)) {
                      method.invoke(obj, args);
                      break;
                  }
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      public void doSomething() {
          System.out.println("woo");
      }
  
      private final static class EntityInvocationHandler implements InvocationHandler,
              ReflectionsInterface {
  
          private Reflections reflectionObj;
  
          public EntityInvocationHandler(Reflections reflectionObj) {
              super();
              this.reflectionObj = reflectionObj;
          }
  
          @Override
          public void doSomething() {
              reflectionObj.doSomething();
          }
  
          @Override
          public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
              Object invoke = method.invoke(this, args);
              return invoke;
          }
  
      }
  }
  </code></pre>
  
  <p>I am unable to understand the when i would get <em>argument type mismatch</em> and the <em>ClassCastException</em> would be caused.
  <strong>I am not able to re-create the exception and would like to know why it comes. Any working code that re-created it, or a source code reference throwing this exception in this case will be good</strong></p>
  
  <p>I have gone through the Method.class javadocs and source code, i am not able to figure out why this error comes.</p>