我已經寫了這個測試類,我想知道爲什麼代理對象有像原始對象一樣的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