Quantcast
Channel: User Federico klez Culloca - Stack Overflow
Viewing all articles
Browse latest Browse all 492

Answer by Federico klez Culloca for Java map.copyOf not using source map comparator

$
0
0

The specification for the copyOf method states

Returns an unmodifiable Map containing the entries of the given Map.

(emphasis mine)

Which means only the entries get copied, nothing else. Hence, it is expected behavior, not a bug.

On the other hand, as suggested in the comments, the documentation for the constructor of the TreeMap class says

Constructs a new tree map containing the same mappings and using the same ordering as the specified sorted map. This method runs in linear time.

Parameters:

m - the sorted map whose mappings are to be placed in this map, and whose comparator is to be used to sort this map

(again, emphasis mine)


Viewing all articles
Browse latest Browse all 492

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>