In many cases Sun does not use a 100% "correct" method to determine when one
object matches another. In the case where an object is not equal to itself (as
defined in its equals method), the implementation will match it anyways.

E.g.

import java.util.*;
public class Test
{
   public static void main(String[] args)
   {
      HashMap<Test,Integer> map = new HashMap<Test,Integer>();
      Test test = new Test();
      map.put(test,1);
      System.out.println(map.get(test));
   }

   public boolean equals(Object o)
   {
      return false;
   }
}

This will return 1.

The package private equals method in classpath (in AbstractMap):
static final boolean equals(Object o1, Object o2)
  {
    return o1 == null ? o2 == null : o1.equals(o2);
  }

Will not match an object with its self if it is not equal to itself.


-- 
           Summary: equals method for collections
           Product: classpath
           Version: 0.18
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: classpath
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: subanark at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24618



_______________________________________________
Bug-classpath mailing list
Bug-classpath@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-classpath

Reply via email to