I want to add some debugging code to an already compiled java class while not touching the original class. I'm thinking of using AspectJ, but I just want to know if it is possible, and if so how?
Example: class A contains void main() which does stuff an开发者_如何学Cd calls method sum(). aspect B adds println() to before A.sum() I want to run class A with aspect B's modification without editing A in any way.
It's possible to do this without touching existing java class (either binary or source), using load-time weaving (LTW).
Please see the official documentation on LTW: http://www.eclipse.org/aspectj/doc/released/devguide/ltw.html
精彩评论