How do I create a new MultiValueMap from Apache Commons Collections?
apache-commons, collections, generics, java
Solution
I believe you're supposed to use
MultiValueMap.multiValueMap(
new TreeMap<String, Collection<Pair<Integer, String>>>());
...not referring to `ArrayList`, since presumably the library wants the freedom to choose which collection implementation it puts in the map.
(That said: if you were to use Guava's `Multimap` instead, you could get this in the much simpler line `MultimapBuilder.treeKeys().arrayListValues().build()` and get the generics automatically inferred.)
Problem
I need a `TreeMap` that can hold multiple values so I chose `MultiValueMap` from Commons Collections 4.0 With HashMap it's easy ``` private MultiValueMap<String, Pair<Integer, String>> foo = new MultiValueMap<String, Pair<Integer, String>>(); ``` but when I want to use some other map implementation like `TreeMap`, The constructor becomes pretty awkward.. ``` //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>>()); ``` now, Eclipse throws me this: ``` The method multiValueMap(Map<K,? super Collection<V>>) in the type MultiValueMap is not applicable for the arguments (TreeMap<String,Pair<Integer,String>>) ``` So, my question is, what does it mean by `Map<K,? super Collection<V>>`? I tried `new TreeMap<String, ArrayList<Pair<Integer, String>>>()` but that didn't work either.