scala中的方法调用拦截
您好,我想知道是否有一种方法可以反射(或以其他方式)截获发送到类的所有方法调用。我知道可以使用Dynamic截取未知的方法,但是类中已经定义的方法呢 我想找到一种不必修改方法语法的方法(就像在aspects框架中拦截方法一样) 作为我想做的一个例子,想象一下:scala中的方法调用拦截,scala,reflection,method-invocation,method-interception,Scala,Reflection,Method Invocation,Method Interception,您好,我想知道是否有一种方法可以反射(或以其他方式)截获发送到类的所有方法调用。我知道可以使用Dynamic截取未知的方法,但是类中已经定义的方法呢 我想找到一种不必修改方法语法的方法(就像在aspects框架中拦截方法一样) 作为我想做的一个例子,想象一下: class A extends AProxy { def foo = println("do something") } class AProxy extends Dynamic { def captureKnownM
class A extends AProxy {
def foo =
println("do something")
}
class AProxy extends Dynamic {
def captureKnownMethods = {
//Capture all methods defined in A
}
def applyDynamic(args) = {
//Capture unknown methods
}
}
参见Scala Macwire
A myclass = new A
myclass.foo //method call captured by captureKnownMethods
myclass.bar //method call captured by applyDynamic