I have the following code:
@Override
public boolean putAll(Multimap<? extends Index, ? extends V> multimap) {
for (Index index : multimap.keySet()) {
putAll(index, multimap.get(index));
}
}
Where multimap.get(index) is a compilation error:
The method get(capture#5-of ? extends Index) in the type Multimap is not applicable for the arguments (Index)
Have I stumbled upon a famous generics gotcha? I don’t quiet see what the problem can be.
Side note: I’m building a class that extends SetMultiMap because I have specific key matching requirements
Suppose you put in a
Multimap<FooIndex, Integer>. Then you’ve got:That’s a type failure, because
Multimap.gettakes aKey. I suspect you need to make this method generic:(I haven’t tested it, but that makes more sense, IMO.)