Regarding Java TreeMap method (or NavigableMap interface):
public SortedMap<K,V> headMap(K toKey)
public NavigableMap<K,V> headMap(K toKey, boolean inclusive)
Why do they return different types? I know SortedMap is super to NavigableMap, I just want to know why an inclusive flag requires a different return.
Looking at the code makes no sense either as the version without the inclusive flag simply calls the other.
Thanks.
I think the reason is historic. TreeMap itself and headMap(K) date back to Java 1.2, whereas NavigableMap and headMap(K, boolean) have been introduced in Java 1.6.
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