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

Description of "consistent with equals" is misleading

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • core-libs

      The Comparable Specification contains the following text:

        A class's natural ordering is said to be consistent with equals if
        and only if (e1.compareTo((Object)e2)==0) has the same boolean value
        as e1.equals((Object)e2) for every e1 and e2 of class C.

      This confuses some readers into thinking that the equals and compareTo should have the same exception behavior, but the general contracts for these methods demand that they do not. For example obj.equals(null) must return false for any non-null obj, but obj.compareTo(null) may thrown an exception. The above description should be amended to take this into account.




        

            jjb Josh Bloch (Inactive)
            jjb Josh Bloch (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: