[英]Java NavigableMap why is headMap return different for same methods
Regarding Java TreeMap method (or NavigableMap interface): 关于Java TreeMap方法(或NavigableMap接口):
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.
我知道SortedMap对于NavigableMap是超级的,我只是想知道为什么包含标志需要不同的回报。
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. TreeMap
本身和headMap(K)
可以追溯到Java 1.2,而NavigableMap
和headMap(K, boolean)
已经在Java 1.6中引入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.