JDK-4521038 : (coll spec) Clarify that ArrayList.contains uses "equals"
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2001-10-30
  • Updated: 2012-10-08
  • Resolved: 2005-09-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 6
6 b51Fixed
Description
Name: rmT116609			Date: 10/30/2001



The description of the java.util.ArrayList.contains(Object o) method is:
"Returns true if this list contains the specified element"

This would seem to imply that true will be returned if and only if the ArrayList contains
an object e such that o and e refer to the same object, but from the description of the 
methods it implements/overrides and from testing it is clear that it the condition is
actually (o==null ? e==null : o.equals(e)).

In order to increase clarity I think the description for ArrayList.contains (and possibly 
other methods) should specify that the equals method is used for object comparision,
 perhaps along the same line as in java.util.List.contains:
"Returns true if this list contains the specified element. More formally,
returns true if and only if this list contains at least one element e such
that (o==null ? e==null : o.equals(e))."
or less formally:
"Returns true if this list contains the specified element, testing for
equality using the equals method."
(Review ID: 134645) 
======================================================================

Comments
EVALUATION Will be fixed as part of jsr166x project
2005-08-05