IdentityHashMap emulation

Skip to first unread message

Christopher Venning

Jan 18, 2008, 3:25:59 PM1/18/08
to Google Web Toolkit
I have use for an identity-based map implementation in my
application. The specific need is not really all that important; but
needless to say, an equality-based map implementation would not work
properly. My concern is, why does GWT not emulate
java.lang.IdentityHashMap? There are two possible reasons I can think
of, but my lack of JavaScript knowledge means I cannot answer my own

Explanation #1: JavaScript does not support identity comparison. In
which case, a workaround is necessary. The equals() method for the
keys' class would have to be overloaded to check against an identity
(in the RDBMS-sense of the word). This would, most likely, involve an
identity factory passing out values to newly-instantiated key objects.

Explanation #1: JavaScript handles the difference between identity
and equality properly. IdentityHashMap was not emulated for library
brevity, the original team believing, rightfully, that few developers
have need for it. If this is the case, an existing implementation
(such as Apache Commons' IdentityMap) needs to be used, or a new
implementation needs to be contributed to the GWT emulation library.

I could, and will, play around testing this; but, I would prefer to
hear it from someone who knows better. The answer would also affect
my understanding of other java.util emulations (such as Collection)
that, according to the contracts stipulated in the Sun API, utilize
equality (equals) over identity (==). My understanding assumes that
GWT does, indeed, call an equals() method in the collections
implementations and that element classes with overwritten equals()
methods function properly during comparison.

Any help would be much appreciated.
Reply all
Reply to author
0 new messages