简体   繁体   中英

Java NavigableMap why is headMap return different for same methods

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM