问题
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.
回答1:
ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.get("OriginalName");
cc.setName("NewName");
cc.writeFile();
回答2:
Works fine for me like this:
javassist.ClassPool.getDefault()
.getAndRename("com.example.Foo", "com.example.Bar")
.toClass();
来源:https://stackoverflow.com/questions/8005805/how-to-create-a-copy-of-a-class-with-javassist