如何扩展最终课程?(Reflection,Javassist) [英] How to extend a final class?(Reflection, Javassist)

查看:81
本文介绍了如何扩展最终课程?(Reflection,Javassist)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆