title: Java javassist method calling
body: <p>So I'm using java agent with javassist for purpose of injecting some small monitoring related code to different methods in different classes. </p>
  
  <p>My java agent code:</p>
  
  <pre><code>public class ConverterAgent implements ClassFileTransformer {
  
  public static void premain(String args, Instrumentation instrumentation){
      System.out.println("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Intializing Java agent &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;");
      ConverterAgent transformer = new ConverterAgent();
      instrumentation.addTransformer(transformer);
  
  }
  
  public static void agentmain(String args, Instrumentation instrumentation){
      System.out.println("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Intializing Java agent &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;");
      ConverterAgent transformer=new ConverterAgent();
      instrumentation.addTransformer(transformer); 
  }
  
  
  @Override
  public byte[] transform(final ClassLoader loader, 
          String className, 
          Class&lt;?&gt; classBeingRedefined, 
          ProtectionDomain protectionDoman, 
          byte[] classFileBuffer)
                  throws IllegalClassFormatException {
  
  
  
  //javassist code goes here
  
  
  return classFileBuffer;
  
  }
  
  }
  </code></pre>
  
  <p>And my javassist injections look like this:</p>
  
  <pre><code>if ("className1".equals(className)){
  
  //code
  
  }
  
  
   if ("className2".equals(className)){
  
  //same code as in first class
  
  }
  
  
  if ("className3".equals(className)){
  
  //same code as in first and second class
  
  }
  </code></pre>
  
  <p>So I'm injecting the same exact code multiple times, I want to optimize my process and call a method for every injection so I don't have to copy same code all over and over again. But here's where I hit my problem, what Method Type am I supposed to use and what arguments does it need besides Class and Method names.    </p>