title: invoke a method using Javassist
body: <p>I'm a newbie to Javassist and trying few tutorials. I understand that Javassist helps to manipulate bytecode and helps achieving structural reflection. As mentioned in wiki (<a href="http://en.wikipedia.org/wiki/Javassist" rel="nofollow">http://en.wikipedia.org/wiki/Javassist</a>), I believe it does have support to achieve reflection. </p>
  
  <p>I'm trying to do a basic evaluation to understand howmuch time would java reflection takes to invoke a method and howmuch time would javassist takes. In the process, assume I have a class: </p>
  
  <pre><code>public class Addition {
  
    public int add(int a, int b){
       return a+b;
    }
  }
  </code></pre>
  
  <p><strong>Now, using java reflection api, I would use the following code to calculate howmuch time will be taken to invoke 100 objects:</strong></p>
  
  <pre><code>import java.lang.reflect.*;
  
  public class ReflectionClass {
  
    /**
     * @param args
     */
    public static void main(String[] args) {
      int numberOfObjects = 10000;
      double start,time;
      try {
  
        Class cls = Class.forName("Addition");
        Class partypes[] = new Class[2];
         partypes[0] = Integer.TYPE;
         partypes[1] = Integer.TYPE;
         Method meth = cls.getMethod(
           "add", partypes);
         Addition methobj = new Addition();
         Object arglist[] = new Object[2];
         arglist[0] = new Integer(37);
         arglist[1] = new Integer(47);
  
  
         start = System.currentTimeMillis();
         for(int i=0;i&lt;numberOfObjects;i++){
           Object retobj= meth.invoke(methobj, arglist);
           Integer retval = (Integer)retobj;
           System.out.println(retval.intValue());
         }
  
         time = System.currentTimeMillis() - start;
  
         System.out.println("Method call for "+numberOfObjects +" objects is::"+time +" milliseconds");
      }
      catch (Throwable e) {
         System.err.println(e);
      }
    }
  
  }
  </code></pre>
  
  <p>Now, I'm not sure how to proceed with javassist. i.e., </p>
  
  <p>I will create a ctclass object and store the class I'm going to read. and I could also get all the declaredmethods using getdeclaredmethods and store it in a ctMethod variable. </p>
  
  <p>But, unlike java reflection api, I can't find an invoke method in ctMethod api of javassist. Does this mean, I've to create a duplicate method and have to make a call to the original method as explained in: <a href="http://www.ibm.com/developerworks/java/library/j-dyn0916/index.html" rel="nofollow">http://www.ibm.com/developerworks/java/library/j-dyn0916/index.html</a>.</p>
  
  <p>I'm not sure if this is the right way to proceed. </p>
  
  <p>Am I missing something?</p>