does the above command produce a deep copy of a LinkedHashMap's elements?
+1
A:
In Java, clone()
is almost always shallow. This is for two reasons:
- Performance
- Not every object defines a working
clone()
method, so deep copying isn't always possible.
Aaron Digulla
2010-01-13 17:27:13
Unless overridden to do something else.
Steve Kuo
2010-01-13 17:30:16
+1
A:
LinkedHashMap
derives from HashMap
, which specifies this for the clone() method:
Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned.
(So no, it's a shallow clone rather than deep. Not that it really matters for the strings.)
Jon Skeet
2010-01-13 17:28:04