JDK-5006670 : RFE: Please provide java.util.Objects utility class
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_9
  • CPU: sparc
  • Submitted: 2004-03-02
  • Updated: 2011-08-17
  • Resolved: 2011-08-17
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 Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 03/02/2004


A DESCRIPTION OF THE REQUEST :
package java.util;

public class Objects {
    public static boolean equals(Object o1, Object o2) {
        if (o1 == null)
            return o2 == null;
        if (o2 == null)
            return false;
        return o1.equals(o2);
    }
    public static int hashCode(Object o) {
        return (o == null) ? 0 : o.hashCode();
    }
    public static <T extends Comparable> int compare(T o1, T o2) {
        if (o1 == null)
            return o2 == null ? 0 : -1;
        if (o2 == null)
            return 1;
        return o1.compareTo(o2);
    }
}

JUSTIFICATION :
Everybody needs at least the first of the above function sooner or later.
I would bet that this Objects.equals() function is already implemented
privately in at least at 100 different places in the JDK.

Let's continue the great traditions of Collections and Arrays utility classes.
(Incident Review ID: 241124) 
======================================================================

Comments
EVALUATION It does make sense to provide this sort of functionality. Incidentally, the first of these methods can be implemented more efficiently: public static boolean equals(Object o1, Object o2) { if (o1 == o2) return true; if (o1 == null) return false; return o1.equals(o2); } The third method (for Comparable) isn't right: it implies that null is less than every other element in their natural ordering. In facts it's incomparable, and compareTo *should* throw NullPointerException when comparing an non-null value to null or vice versa. ###@###.### 2004-03-14
14-03-2004