Search code examples
javajavassist

How to create a copy of a class with javassist?


With Javassist, how can I create an absolutely the same class as the one I have, but with a different name. I want to preserve all runtime annotations as well.


Solution

  • ClassPool pool = ClassPool.getDefault();
    CtClass cc = pool.get("OriginalName");
    cc.setName("NewName");
    cc.writeFile();