How to create a copy of a class with javassist?

不想你离开。 提交于 2019-12-22 11:34:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!