United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6693509 Deep Cloning for Map
JDK-6693509 : Deep Cloning for Map

Details
Type:
Enhancement
Submit Date:
2008-04-24
Status:
Closed
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2010-11-21
Component:
core-libs
OS:
windows_xp
Sub-Component:
java.util
CPU:
x86
Priority:
P5
Resolution:
Won't Fix
Affected Versions:
7
Fixed Versions:

Related Reports

Sub Tasks

Description
A DESCRIPTION OF THE REQUEST :
Map is not able to do the deep cloning, while calling the clone() method on it.. It just uses the reference copy, not creating the another cloneed object.

JUSTIFICATION :
This feature should be there because, if i need another map very similar to the same map and i want to retain the first map as static and changing the cloned map, the actual map should not be change.
  To do this, clone() method in the collection object need to be changed to perfrom deep cloning insteed of just copying the same references. Either modify clone() method or need to introduce another method to do this stuffs.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The Actual map should not changed, when ever i am changing the cloned map.
ACTUAL -
The Actual map is also getting changed, when ever i am changing the cloned map.

                                    

Comments
PUBLIC COMMENTS

Deep cloning is intentionally not provided by the Collections classes. If deep cloning is desired it should be performed by the application.

Consider the following typical deep clone implementation:

Map newMap = new Map(oldMap.size());
for(Map.Entry entry : oldMap.entrySet()) {
  newMap.put(entry.getKey(), entry.getValue().clone());
}

Perhaps the keys should have been cloned as well? The semantics required depend too much on the application and the characteristics of the keys and values for a one size fits all deepClone to be practical.
                                     
2010-11-21



Hardware and Software, Engineered to Work Together