title: How to remove a method using Javassist?
body: <p>I am trying to <strong>delete</strong> a method from a class file using Javassist.</p>
  
  <p>Target class:<code>"RemoveMethod"</code>.</p>
  
  <p>Target method:<code>"DoubleCheck"</code>.</p>
  
  <p>My codes:</p>
  
  <pre><code>package javassist;     
          import java.io.IOException;
          import java.lang.reflect.Method;
          import javassist.*;
  
  public class cRepair {
      public static void main(String[] args) throws NotFoundException, IOException, CannotCompileException{
      ClassPool pool = ClassPool.getDefault();  
      CtClass ctClass = pool.get("javassist.RemoveMethod");  
      CtMethod ctm = ctClass.getDeclaredMethod("DoubleCheck");  
      ctClass.removeMethod(ctm);
      ctClass.writeFile("C:/Users/workspace/Javaproject1/src/javassis"); 
   }
  }
  </code></pre>
  
  <p>Then,run the code using the file "javassist.jar":  </p>
  
  <pre><code>javac -cp javassist.jar cRepair.java
  </code></pre>
  
  <p>Then check the target class:</p>
  
  <pre><code>javap -verbose RemoveMethod.class
  </code></pre>
  
  <p>The method "DoubleCheck" is still there!</p>
  
  <p>This looks really odd. Why could this happen and how to fix it?</p>