Hi Justin,

In the latest snapshot, there is a hashCode() method for every equals()
method. Actually, the equals() methods all rely on hashCode() using a logic
like:

        public boolean equals(Object object)
        {
                return (object instanceof Cookie) 
                    && (((Cookie) object).hashCode() == hashCode());
        }

The hashCode() implementations use a logic identical to List.hashCode():

        public int hashCode()
        {
                return Factory.hashCode(super.hashCode(), getVersion(),
getPath(), 
                                                getDomain());
        }

Implemented in a Factory.hashCode() method:

        public static int hashCode(Object... objects)
        {
                int result = 1;

                if (objects != null)
                {
                        for (Object obj : objects)
                        {
                                result = 31 * result + (obj == null ? 0 :
obj.hashCode());
                        }
                }

                return result;
        }

What Piyush points out is that the algorithm in List.hashCode() isn't fully
discriminating (as I assumed).

Best regards,
Jerome  

> -----Message d'origine-----
> De : news [mailto:[EMAIL PROTECTED] De la part de Justin C. 
> van Vorst
> Envoyé : jeudi 16 novembre 2006 03:59
> À : [email protected]
> Objet : Re: equals and hashcode
> 
> That there is no hashCode() method accompanying the equals() 
> method is one
> problem.  The other is that the equals() method may fail the 
> commutative
> property test whereby cookieA.equals(childOfCookieB) == true, but
> childOfCookieB.equals(cookieA) == false.

Reply via email to