JDK-4391067 : unmodifiable factory methods should check if the collection is already immutable
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.2.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2000-11-21
  • Updated: 2021-03-03
  • Resolved: 2021-03-03
Related Reports
Duplicate :  
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.

Comments
EVALUATION Seems harmless enough, though it's not clear that it's worth doing. joshua.bloch@Eng 2000-11-20
20-11-2000