Simplify java.util.Object.equals - remove the identity comparison

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • tbd
    • Affects Version/s: 25
    • Component/s: core-libs
    • None

      The typical implementation of the `equals` method for a class, test for object identity using the `== operator` and then compares the state with the other object's state.
      In a very small fraction of the comparisons, the other object has the same identity and there is some benefit to the extra `==` comparison. The rest of the time that identity comparison is wasted effort.

      This enhancement proposes to drop the un-beneficial use of `==` when followed by calling `equals`.

      The `java.util.Objects.equals` utility for comparing two objects, uses the same pattern, testing for identity before delegating to the object's `equals` method. There is even less benefit in this case, since many implementations of `equals` also use `==` as the first condition. The redundant identity comparison should be reduced.

      The Valhalla project tested this premise and did not see a performance regression as a result of removing the identity comparison from `Objects.equals`.

            Assignee:
            Roger Riggs
            Reporter:
            Roger Riggs
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: