我已经写了这个测试类,我想知道为什么代理对象有像原始对象一样的hashCode。有谁知道为什么?Java代理 - >为什么代理对象像原始对象一样hashCode
public class Main {
public static void main(String[] args) {
final Service realSubject = new Subject_A();
final Service proxySubject = ProxyGenerator.makeProxy(Service.class, realSubject);
final String hello = proxySubject.work("Hello");
System.out.println("hello = " + hello);
System.out.println("\n");
System.out.println("realSubject: " + realSubject);
System.out.println("proxySubject: " + proxySubject);
}
}
那是一个输出样本:
in Subject_A#work: str = Hello
hello = Hello_DONE
realSubject: [email protected]
proxySubject: [email protected]
你不会在你的代码中调用'.hashCode()',所以我看不到你期望的答案。请输出样品? – fge
什么是“服务”,“主题A”和“代理生成器”?这些来自某个图书馆还是你写的? – Codebender
可能重复[在Java中重写equals和hashCode时应考虑哪些问题?](http://stackoverflow.com/questions/27581/what-issues-should-be-considered-when-overriding-equals-and- hashcode-in-java) – Raedwald