[英]java execute hook code before method return
I would like to have a post hook that is run before a method return. 我想有一个在方法返回之前运行的post钩子。 It should be possible add a hook to any method without modifying existing code. 应该可以在不修改现有代码的情况下将钩子添加到任何方法。 Is there a tool or technology that helps realise this? 有没有工具或技术可以帮助实现这一目标? Is javassist a candidate here? Javasist是这里的候选人吗? If yes, how to pass parameters to the hook? 如果是,如何将参数传递给钩子? Ideally whatever the method returns should be passed as parameter to the hook. 理想情况下,无论方法返回什么,都应将其作为参数传递给挂钩。
Yes, the technique is called byte code engineering. 是的,该技术称为字节码工程。 There are several popular tools. 有几种流行的工具。 The most famous higher level tool is called AspectJ. 最著名的高级工具称为AspectJ。
However there are lower level tools like CGLIB, Javassiste, BCEL. 但是,还有一些较低级别的工具,例如CGLIB,Javassiste,BCEL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.