Correction:
Your use of Test3.map()
doesn't provide type arguments and there is no way for the compiler to infer the type arguments. The JLS says the following when failing to infer type arguments
Any remaining type variable
T
that has not yet been inferred is then inferred to have typeObject
.
So the method invocation looks like
Map<Object, Object> object = Test3.map();
f(object); //not valid
which is confirmed by what the error message from the compiler says:
incompatible types:
java.util.Map<java.lang.Object,java.lang.Object>
cannot be converted tojava.util.Map<java.lang.String,java.lang.Integer>
the generic type arguments default to Object
.
You can fix it by specifying the type arguments
f(Test3.<String, Integer>map()); // valid