以下のように 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を出力しますか?