我需要一个能够容纳多个值的
TreeMap
,因此我选择了 Commons Collections 4.0 中的 MultiValueMap
。
使用 HashMap 很容易。
private MultiValueMap<String, Pair<Integer, String>> foo =
new MultiValueMap<String, Pair<Integer, String>>();
但是当我想使用其他地图实现,比如 TreeMap
时,构造函数变得相当笨拙。
//they hide MultiValueMap(Map map, Factory factory),
//so I'll have to use static multiValueMap(...) instead
private MultiValueMap<String, Pair<Integer, String>> directoryMap=
MultiValueMap.multiValueMap(new TreeMap<String, Pair<Integer, String>>());
现在,Eclipse 抛出了这个错误:
The method multiValueMap(Map<K,? super Collection<V>>) in the type MultiValueMap is not
applicable for the arguments (TreeMap<String,Pair<Integer,String>>)
所以,我的问题是,Map<K,? super Collection<V>>
是什么意思?
我尝试了new TreeMap<String, ArrayList<Pair<Integer, String>>>()
,但那也不起作用。
MultiValueMap
中?此外,Pair
是自定义类吗? - Sotirios Delimanolisput()
方法将覆盖旧值。 - tom91136