title: Create a clone of a static constructor with Javassist
body: <p>It seems that Javassist's API allows us to create an exactly copy of the class initializer (ie., static constructor) declared in a class:</p>
  
  <pre><code>CtClass cc = ...;
  CtConstructor staticConstructor = cc.getClassInitializer();
  if (staticConstructor != null) {
    CtConstructor staticConstructorClone = new CtConstructor(staticConstructor, cc, null);
    staticConstructorClone.getMethodInfo().setName(__NEW_NAME__);
    staticConstructorClone.setModifiers(Modifier.PUBLIC | Modifier.STATIC);
    cc.addConstructor(staticConstructorClone);
  }
  </code></pre>
  
  <p>however, that copy also includes (public/private) static <strong>final</strong> fields. for example, the static constructor of the following class:</p>
  
  <pre><code>public class Example {
    public static final Example ex1 = new Example("__EX_1__");
  
    private String name;
  
    private Example(String name) {
      this.name = name;
    }
  }
  </code></pre>
  
  <p>is in fact:</p>
  
  <pre><code>static {
    Example.ex1 = "__NAME__";
  }
  </code></pre>
  
  <p>and therefore, an exactly copy of the static constructor will also include that call to the final field "name".</p>
  
  <p>Is there any way of creating a copy of a static constructor which does not include calls to final fields?</p>
  
  <p>-- Thanks </p>