- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Re: equality questions
Wed, 2009-09-23, 09:53
martin odersky wrote:
> Are there alternatives? The most obvious generalization is to make ==
> a multi-method.
> That's similar to the current scheme, except that we should avoid any
> leakage into equals. We have to make sure that equals only ever calls
> equals, never ==.
Why? Why can't == be used in equals if a hash code function that is consistent with it is also used?
/Jesper Nordenberg
On Wed, Sep 23, 2009 at 10:53 AM, Jesper Nordenberg wrote:
> martin odersky wrote:
>> Are there alternatives? The most obvious generalization is to make ==
>> a multi-method.
>> That's similar to the current scheme, except that we should avoid any
>> leakage into equals. We have to make sure that equals only ever calls
>> equals, never ==.
>
> Why? Why can't == be used in equals if a hash code function that is consistent with it is also used?
>
That would work of course. But remember we are dealing with boxed
numbers here and the hashCode
for them is imposed on us.
Cheers