[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -isEqual: equals '==' ?

From: Richard Frith-Macdonald
Subject: Re: -isEqual: equals '==' ?
Date: Sun, 19 Oct 2003 06:41:20 +0100

On Sunday, October 19, 2003, at 06:24 AM, Yen-Ju Chen wrote:


 Is -isEqual: the same as '==' ?

No (though it might be implemented that way for a particular class).

 Since -isEqual: is defined in NSObject and '==' is in compiler,
 they seem not the same.
Then in NSDictionary, which one does it use to get the object by comparing key ?
 -isEqual: or '==' ?

the -isEqual: method.

 From Apple's document, overriding -isEqual: requires overriding -hash.
 Does it apply in GNUstep ?

Maybe ...
the -isEqual: method compares its argument with the receiver ...
and the actual comparison mechanism used depends on the receiving object
of course. Some classes may implement it to use the fact that if the hash of the receiver and the has of the argument differ, the two cannot be equal.
Other classes may not use the -hash method at all.
You should certainly ensure that -isEqual: and -hash are consistent ... so if you override one you may need to override the other. Two object which are equal should also have the same hash, though two objects with the same hash are
not necessarily equal.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]