> I don't get it. That was the whole point of adding the
> System.identityHashCode() method to 1.1. It was designed
> to return a UID in the case that a class overloaded
> the hashCode() method. Now folks seem to be saying "oh,
> yeah that was changed for 1.2". Changed to what?
> How would you suggest I generate a UID for two
> different object of the same class that return
> the exact same hash code? I can't get the memory
> location to implement my own UID method.
Nope, the whole point of System.identityHashCode() was added so that == had
equivalent operators to Object.equals(Object). Essentially it allowed you to
create an identity hash table. If they had ment it to be a uid they would
have called it Object.getUid(). ;-)
> I guess I could create another table of objects
> that map to the same hashCode but are not equal.
> It might also be possible to map every id to
> a Vector instead of directly to the object.
> Both of these "solutions" would be really ugly.
> I am really getting sick of Sun changing the
> APIs in really sneaky ways.
They didn't change the API. The docs have been the same for quite some time.
They did fix a conflict in the spec that said the following:
1) Object.equals(Object) returns true if two objects are equivalent.
2) Object.hashCode() always returns the same value for the same object.
3) if a.equals(b) then a.hashCode() == b.hashCode()
They realized that #2 couldn't always be true if #1 & #3 were true. That's
the only change I'm aware of with this API.
Standard hashtables are based on Object.equals() and as such deal with the
hashCode collision issue. So, if you just use a standard Hashtable (or Set
depending on your needs), make sure you're using identityHashCode() and
=='s, then collisions will be dealt with for you.
The thing to keep in mind is that hashCode() is generally speaking an
optimization, something that speeds up lookups, rather than being an
outright property of an object.
If you need is simply have an ID based lookup mechanism for objects in
memory, you can just use a double-WeakHashtable and some kind of a counter.
--Chris
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]