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

Wrong method specification for contains() in java.util.TreeSet

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 8, 11, 17
    • core-libs

      A DESCRIPTION OF THE PROBLEM :
      The method specification for contains() in java.util.TreeSet reads:
      More formally, returns true if and only if this set contains an element e such that Objects.equals(o, e).
      However, this is not how TreeSet is implemented. Based on my testing, TreeSet uses the comparable to determine equality, instead of Objects.equals().
      Although this is noted in the class specification of TreeSet, it is still VERY confusing for developers and thus should be corrected by revising the method spec for contains().


      FREQUENCY : always


            smarks Stuart Marks
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: