Java – is there any way to listen to the method execution of another class?

Can I listen to the method execution of an instance or all instances of a class without modifying the code?

someInstance.addMethodExecutionListener('methodName',handler);
SomeClass.addMethodExecutionListener('methodName',handler);

It will be used for recording purposes

Solution

Your question is a small part of what you can do with aspect - oriented programming It is not supported in ordinary Java and its implementation, but it is the core reason of AspectJ

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>