如果我实现了一些 MethodInterceptor 如下:
public class HashCodeAlwaysZeroMethodInterceptor implements MethodInterceptor {
public Object intercept(Object object, Method method, Object[] args,
MethodProxy methodProxy) throws Throwable {
if ("hashCode".equals(method.getName())) {
return 0;
}
return methodProxy.invokeSuper(object, args);
}
}
Object proxy = Enhancer.create(
Object.class,
new HashCodeAlwaysZeroMethodInterceptor());
现在是否增强了 Object 的每个实例?IE:如果我做类似的事情:
class foo { foo(){} }
foo myfoo = new foo();
int hash = myfoo.hashCode();
System.io.println(hash); //Prints 0
它真的会打印0吗?