修改静态方法的返回值
Modifying the returned value of a static method
我需要拦截对静态方法的方法调用。我的新方法需要调用该方法的原始实现,用它 returns 和 return 修改后的值做一些工作。
我的问题是 "invoke the original implementation of the method" 部分,我该怎么做?一些文档阅读和谷歌搜索似乎表明我需要将 Advice 与 @Origin 或 @SuperMethod 一起使用,但我一直无法找到如何以允许我 return 修改值的方式创建 Advisor。
有什么指点吗?
如果您使用 Advice
,则必须使用特定于通知的注释:
class SomeAdvice {
@Avice.OnMethodEnter
static void enter() {...}
@Advice.OnMethodExit
static void exit(@Advice.Return(readOnly = false) Object val) {
val = "some other value";
}
}
您似乎将 MethodDelegation
的概念融入此处的建议中。然而,这两者非常不同。建议在方法前后添加代码,委托替换方法。
我需要拦截对静态方法的方法调用。我的新方法需要调用该方法的原始实现,用它 returns 和 return 修改后的值做一些工作。
我的问题是 "invoke the original implementation of the method" 部分,我该怎么做?一些文档阅读和谷歌搜索似乎表明我需要将 Advice 与 @Origin 或 @SuperMethod 一起使用,但我一直无法找到如何以允许我 return 修改值的方式创建 Advisor。
有什么指点吗?
如果您使用 Advice
,则必须使用特定于通知的注释:
class SomeAdvice {
@Avice.OnMethodEnter
static void enter() {...}
@Advice.OnMethodExit
static void exit(@Advice.Return(readOnly = false) Object val) {
val = "some other value";
}
}
您似乎将 MethodDelegation
的概念融入此处的建议中。然而,这两者非常不同。建议在方法前后添加代码,委托替换方法。