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.
TreeMapitself andheadMap(K)date back to Java 1.2, whereasNavigableMapandheadMap(K, boolean)have been introduced in Java 1.6.