• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDictionary, keys, and equals
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary, keys, and equals


  • Subject: Re: NSDictionary, keys, and equals
  • From: Art Isbell <email@hidden>
  • Date: Wed, 25 Feb 2004 16:39:56 -1000

On Feb 25, 2004, at 2:24 PM, Jonathan Rochkind wrote:

I have implemented a custom equals() on that custom object class. (Don't worry, it's not an EO).

My impression was, if I stored an object in an NSMutableDictionary under a certain key, it would be retrievable not only by that exact same object (identity ==) as a key, but by _another_ object of the same type that equals() the first object, even if it doens't == the first object.

However, this does not seem to be the case. What's up with that?

Is it the mysterious hashCode()? Cause I haven't actually provided a custom implementation of hashCode(), I'm just using whatever java.lang.Object gives me. Is this the problem?

That would be my guess because the method description for Object.hashCode() states:


"As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)"

So where object1 == object2, equals() is true and hashCode() returns the same value. But where object1.equals(object2) is true and object1 == object2 is false, hashCode() will return different values for each object which may cause NSDictionary to consider the keys to be different.

Aloha,
Art
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: NSDictionary, keys, and equals
      • From: Adam Ramadan <email@hidden>
References: 
 >NSDictionary, keys, and equals (From: Jonathan Rochkind <email@hidden>)

  • Prev by Date: Re: Is WebObjects Dead?
  • Next by Date: Re: Is WebObjects Dead?
  • Previous by thread: NSDictionary, keys, and equals
  • Next by thread: Re: NSDictionary, keys, and equals
  • Index(es):
    • Date
    • Thread