XPCOMJavaProxy.hashCode() has huge problem
"Eric Suen" <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Message-ID | <Bfudnc0UgYzqyzjZnZ2dnUVZ_sednZ2d__28103.103899821$1151686518$gmane$org@mozilla.org> |
Hi all,
Here the code:
nsIDOMElement div = document.createElement("div");
nsIDOMElement br = document.createElement("br");
div.appendChild(br);
nsIDOMNode node = div.getFirstChild();
Object hbr = node.queryInterface(
nsIDOMHTMLBRElement.NS_IDOMHTMLBRELEMENT_IID
);
System.out.println(node.hashCode() == br.hashCode());
System.out.println(hbr.hashCode() == br.hashCode());
System.out.println(hbr.hashCode() == node.hashCode());
System.out.println(node.queryInterface(
nsIDOMElement.NS_IDOMELEMENT_IID
).hashCode() == br.hashCode());
System.out.println(hbr.equals(br));
System.out.println(node.equals(br));
The result is:
false
false
false
true
true
true
In java, if two object is equals, the hashCode should be same, because
it is necessary for HashMap, but two object hashCode is same, but they
may not equals.
but use java xpcom, that means we must cast to the right interface,
otherwise, you can not use hashmap, so, how do I know which interface
should I use?
Eric