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

unmodifiable factory methods should check if the collection is already immutable

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.1
    • core-libs
    • None

      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.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: