|
From: Troy G. <tro...@gm...> - 2011-03-18 15:44:14
|
Hello everyone,
It seems like the java.util.HashMap might be implemented incorrectly.
Either that, or I'm not seeing something. Below is the implementation. I
had some code that was cross-compiled over which had the equals method and
hashCode method implemented correctly.
During the program run, it could not find User instances in the map. What I
discovered is this was only a problem when the User instances were separate
references even though the equals method and hashCode was correct.
I'm thinking the [NSValue valueWithPointer:key] compares references and not
the underlying values (in this case User). Has anyone seen this same issue?
This may not even be a problem in the new C back-end, but I'm curious what
you guys think. The only solution I could come up with is to wrap the key
in something else and forward the isEqual and hash methods.
- (java_lang_Object*)
put___java_lang_Object_java_lang_Object:(java_lang_Object*) key:
(java_lang_Object*) value {
java_lang_Object* oldObj = [self get___java_lang_Object:key];
id k = [key conformsToProtocol: @protocol(NSCopying)] ? key : [NSValue
valueWithPointer: key];
[self setObject:value forKey:k];
return oldObj;
}
Thanks again for all the great work!
|