United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4521038 : (coll spec) Clarify that ArrayList.contains uses "equals"

Details
Type:
Bug
Submit Date:
2001-10-30
Status:
Resolved
Updated Date:
2012-10-08
Project Name:
JDK
Resolved Date:
2005-09-04
Component:
core-libs
OS:
generic
Sub-Component:
java.util:collections
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.0
Fixed Versions:

Related Reports

Sub Tasks

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



Hardware and Software, Engineered to Work Together