In this example:
import java.util.*;
public class Example {
static void doesntCompile(Map> map) {}
static &l
In the call:
compiles(new HashMap>());
T is matched to Integer, so the type of the argument is a Map
. It's not the case for the method doesntCompile
: the type of the argument stays Map
whatever the actual argument in the call; and that is not assignable from HashMap
.
UPDATE
In the doesntCompile
method, nothing prevents you to do something like this:
static void doesntCompile(Map> map) {
map.put(1, new ArrayList());
}
So obviously, it cannot accept a HashMap
as the argument.