简体   繁体   English

如何在Guava的Multimap(使用asMap())中使用NavigableMap功能?

[英]How to use NavigableMap features with Guava's Multimap (with asMap())?

Let's assume i have something like this: 我们假设我有这样的事情:

Multimap<Integer, Integer> data = TreeMultimap.create();

How can i use .headMap() on my data? 如何在我的数据上使用.headMap() I suppose, that TreeMultimap.asMap() is the way to go. 我想, TreeMultimap.asMap()是要走的路。

The documentation ( link ) says, that TreeMap.asMap() returns NavigableMap<K,Collection<V>> , but i'm not able to get that to work. 文档( 链接 )说, TreeMap.asMap()返回NavigableMap<K,Collection<V>> ,但我无法使其工作。

NavigableMap<Integer, ArrayList<Integer>> test = data.asMap(); // type mismatch
SortedMap<Integer, ArrayList<Integer>> test = data.asMap(); // type mismatch

What am i doing wrong? 我究竟做错了什么?

Thanks! 谢谢!

PS: I'm using guava 16 PS:我正在使用番石榴16

The type of data is Multimap , not TreeMultimap . data类型是Multimap ,而不是TreeMultimap Also, a NavigableMap<Integer, Collection<Integer>> , is not compatible with NavigableMap<Integer, ArrayList<Integer>> . 此外, NavigableMap<Integer, Collection<Integer>>NavigableMap<Integer, ArrayList<Integer>>不兼容。

Change your code to: 将您的代码更改为:

TreeMultimap<Integer, Integer> data = TreeMultimap.create();
NavigableMap<Integer, Collection<Integer>> test = data.asMap();

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

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