(试图保持简单。)
我有这样的(部分)ByteBuddy食谱:
builder
.method(someMatcher())
.intercept(MethodDelegation.to(this.interceptor));
我有一个这样定义的“拦截器”类:
private static final class Interceptor {
private Interceptor() {
super();
}
@RuntimeType
private final Object doSomething(@This final Proxy<?> proxy,
@SuperCall final Callable<?> callable,
@Origin final String methodSignature) throws Exception {
final Object proxiedInstance = proxy.getProxiedInstance();
// TODO: logic
return callable.call(); // for now
}
}
(由于各种原因(此处不重要,拦截器方法必须为非static
。]
[当我创建此ByteBuddy定义的类的实例并对其调用简单的public void blork()
方法时,我得到:
Cannot resolve ambiguous delegation of public void com.foo.TestExplorations$Frob.blork() to net.bytebuddy.implementation.bind.MethodDelegationBinder$MethodBinding$Builder$Build@3d101b05 or net.bytebuddy.implementation.bind.MethodDelegationBinder$MethodBinding$Builder$Build@1a9efd25
如果只有一个拦截器,怎么会有歧义?我做错了什么?
Byte Buddy只是将一个方法调用添加到已检测类,该方法需要能够查看目标类。如果为private
,则将其忽略,然后Byte Buddy进一步在层次结构中进行搜索,最终它考虑所有均不适合的Object
方法,因此引发了歧义异常,而不是无法绑定任何方法的异常。