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

(coll spec) TreeSet.remove - absence of Compara{ble,tor} throws ClassCastException

    XMLWordPrintable

Details

    Description

      Name: rmT116609 Date: 10/23/2003


      A DESCRIPTION OF THE PROBLEM :
      The method TreeSet.remove(Object o) throws a ClassCastException if the objects collected in the TreeSet and the Object o doesn't implement Comparable or specify a Comparator. The documentation says: "Throws: ClassCastException - if the specified object cannot be compared with the elements currently in the set." It would be nice, if you could be more specific here and tell the user, that he has to implement Comparable or specify a Comparator. There are lot's of questions about this in your community forums.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Throws: ClassCastException - if the specified object cannot be compared with the elements currently in the set.
        To achieve this implement Comparable or create the TreeSet with a Comparator.
      ACTUAL -
      Throws: ClassCastException - if the specified object cannot be compared with the elements currently in the set.

      URL OF FAULTY DOCUMENTATION :
      http://java.sun.com/j2se/1.4.2/docs/api/java/util/TreeSet.html
      (Incident Review ID: 217359)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              martin Martin Buchholz
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: