Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4520573

Object.equals is not well fitted for 'null' comparison

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P3 P3
    • None
    • 1.3.1
    • core-libs
    • generic
    • generic



      Name: nt126004 Date: 10/29/2001


      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)


      Object.equals is not easy to use when you compare two
      object references that can be null.
      I'd rather have a
      static boolean equals(Object o1, Object o2)
      {
         if (o1 == null) {
             if (o2 == null) {
                 return true;
             }
             return o2.equals(o1);
         }
         return o1.equals(o2);
      }
      in the Object class.
      (Review ID: 134567)
      ======================================================================

            iris Iris Clark
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: