Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XPCOMJavaProxy.hashCode() has huge problem

0 views
Skip to first unread message

Eric Suen

unread,
Jun 30, 2006, 12:55:32 PM6/30/06
to
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


Michal Ceresna

unread,
Jul 2, 2006, 1:26:12 PM7/2/06
to dev-te...@lists.mozilla.org
On Friday 30 June 2006 18:55, Eric Suen wrote:
Hello,

> 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

Eric Suen

unread,
Jul 2, 2006, 1:55:21 PM7/2/06
to
>> 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
>

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


Michal Ceresna

unread,
Jul 4, 2006, 3:13:05 PM7/4/06
to dev-te...@lists.mozilla.org
On Sunday 02 July 2006 19:55, Eric Suen wrote:

> 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

Javier Pedemonte

unread,
Jul 5, 2006, 2:12:25 PM7/5/06
to
Eric:

Please follow the discussion in
https://bugzilla.mozilla.org/show_bug.cgi?id=343580 and add any thoughts
you might have. Thanks...


javier

0 new messages