bug-classpath
[Top][All Lists]
Advanced

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

[Bug classpath/24618] New: equals method for collections


From: subanark at gmail dot com
Subject: [Bug classpath/24618] New: equals method for collections
Date: 1 Nov 2005 17:11:53 -0000

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





reply via email to

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