Why don't the treeMap.entrySet() and treeMap.keySet() methods return SortedSet? I might go so far as saying that is a mistake. As per the API, a Set is defined as not having a particular ordering. However, the sets returned by TreeMap do have a particular ordering.
I think if they wrote the interface SortedMap
now, both keySet
and entrySet
would return SortedSet
. However, the SortedMap
interface was introduced in Java 1.2 before covariant return types were allowed. They cannot change this now as there will be implementations of SortedMap
out there for which keySet
and entrySet
returns a Set
that is not a SortedSet
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With