javareflectionbytecodejavassist

How to extend a final class?(Reflection, 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.


Solution

  • You can't use reflection to modify existing class definitions.

    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.