开发者

LinkedHashMap<String,Object>.clone();

开发者 https://www.devze.com 2022-12-16 12:04 出处:网络
does th开发者_如何学Ce above command produce a deep copy of a LinkedHashMap\'s elements?In Java, clone() is almost always shallow. This is for two reasons:

does th开发者_如何学Ce above command produce a deep copy of a LinkedHashMap's elements?


In Java, clone() is almost always shallow. This is for two reasons:

  1. Performance
  2. Not every object defines a working clone() method, so deep copying isn't always possible.


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号