开发者

Modifying existing java class behavior with aspectj?

开发者 https://www.devze.com 2023-02-17 15:09 出处:网络
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?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消