我有一个.JAR文件,其中包含大量的类。我需要将其设置为final,因此无法对其进行扩展。有一种方法,我基本上必须扩展和修复,否则一切都会中断。我怎样才能做到这一点?我知道反射和Javassist可以用于此目的,但我不知道如何使用。只要有效,任何其他工具也是可以接受的。
I have a .JAR file and it has tons of classes. One, that I need is set as final, so I cannot extend it. There is one method, that I basically have to extend and fix, otherwise everything breaks. How can I do that? I know Reflection and Javassist can be used for this, but I have no idea how. Any other tool is also acceptable, as long as it works.
推荐答案您不能使用 reflection 修改现有的类定义。
You can't use reflection to modify existing class definitions.
如果该JAR的许可允许您使用,我建议使用另一种解决方案:反编译该类;删除 final 关键字;并重建类和JAR文件。
If the licence of that JAR allows you to, I would suggest a different solution: decompile that one class; drop the final keyword; and rebuild class and JAR file.
这是解决问题的唯一鲁棒方法。
That is the only robust way to solve your problem.
更多推荐
如何扩展最终课程?(Reflection,Javassist)
发布评论