简体   繁体   English

Java NavigableMap为什么headMap对于相同的方法返回不同

[英]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,而NavigableMapheadMap(K, boolean)已经在Java 1.6中引入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java类有两个具有相同函数签名但返回类型不同的方法 - Java class has 2 methods with the same function signature but different return types 深度复制Java中的NavigableMap - Deep copy a NavigableMap in Java 如何在Java中循环NavigableMap - How to Loop in NavigableMap in Java Java中不可修改的NavigableSet / NavigableMap? - Unmodifiable NavigableSet/NavigableMap in Java? Java中的Treemap的headmap方法 - Treemap's headmap method in Java 如何为同一方法传递不同的 object 类型,而不是在 java 中编写具有相同功能和返回类型的两个方法 - How to pass different object type for same method instead of writing two methods with same functionality and return type in java 为什么Java中不同对象的hashCode()可以返回相同的值? - Why can hashCode() return the same value for different objects in Java? 命名具有不同返回类型但功能相同的方法 - naming methods with different return types but the same functionality Java 8 - 两个接口包含具有相同方法签名但返回类型不同的默认方法,如何覆盖? - Java 8 -Two interfaces contain default methods with the same method signature but different return types, how to override? 调用两种方法以返回Java中的不同页面 - Calling Two Methods To Return Different Pages In Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM