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

unmodifiable factory methods should check if the collection is already immutable

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.2.1
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None

      Description

      Currently all of the unmodifiable... methods in the Collections
      class create a new collections object for their return code even if
      the object was already unmodifiable. A performance enhancement would
      be to test if the delegate collection is already an unmodifiable version
      of the collection and to simply return the original object as the new
      unmodifiable version.

      Also, each call to unmodifiableFoo creates a wrapper object for the
      Foo argument. Calling this multiple times will create multiple wrapper
      objects each of which adds another delegation layer.

      Finally, there is no way for the programmer to work around this problem
      as there is no public way to query if the collection is already unmodifiable.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jjb Josh Bloch
              Reporter:
              flar Jim Graham
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: