Before using google collections I had something similar to next code:
private Set<A> aSet = ...;
private Set<B> bSet = ...;
public Foo getFoo (Map<?, List<Bar>> bars, Set<?> set) {
for (Object item : set) {
for (Bar bar : bars.get (item)) {
//build foo;
}
}
...
}
and I was able to make calls like these:
Map<A, List<Bar> aMap = getAMap ();
Foo f1 = getFoo (aMap, aSet);
Map<B, List<Bar> bMap = getBMap ();
Foo f2 = getFoo (bMap, bSet);
Now, with Multimap, I cannot do the same:
public Foo getFoo (Multimap<?, List<Bar>> bars, Set<?> set) {
for (Object item : set) {
// compile error: get(capture#621 of ?) in Multimap ... cannot be applied to java.lang.Object
for (Bar bar : bars.get (item)) {
//build foo;
}
}
...
}
Try this:
EDIT:
If you see the javadoc for both classes, you will realize that the javadoc for Map is:
and for MultiMap is:
See that the parameter for Map is not generified.
The
MultiMapis better for generic, but Map is designed so it has backward compability with previousMapfrom Java 1.4.