Why does trying to compile
public class GenericsFail {
public static void main(String[] args) {
accept(new HashMap>());
}
public static void accept(Map> multiMap) {}
}
give the error
GenericsFail.java:7: error: method accept in class GenericsFail cannot be applied to given types;
accept(new HashMap>());
^
required: Map>
found: HashMap>
reason: actual argument HashMap> cannot be converted to Map> by method invocation conversion
The wildcard is only allowed if it's not nested inside List.
解决方案
To be more general
void accept(Map> multiMap)