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
> 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?
all objects are children of nsISupports, so QI to nsISupports
Michal
> all objects are children of nsISupports, so QI to nsISupports
>
Thanks,
Your suggestion works, but I also question about the implemention
of the hashCode, because it is annoying that every time I want to use
hashCode, I have to cast to nsISupports.
Eric
> Your suggestion works, but I also question about the implemention
> of the hashCode, because it is annoying that every time I want to use
> hashCode, I have to cast to nsISupports.
opened a new bug with this issue:
https://bugzilla.mozilla.org/show_bug.cgi?id=343580
Michal
Please follow the discussion in
https://bugzilla.mozilla.org/show_bug.cgi?id=343580 and add any thoughts
you might have. Thanks...
javier