Greetings to all! I read from Bruce Eckel about generics, I got the following code as an example:
package net.mindview.util; import java.util.*; public class New { public static <K,V> Map<K,V> map() { return new HashMap<K,V>(); } } public class LimitsOfInference { static void f(Map<Person, List<? extends Pet>> petPeople) {} public static void main(String[] args) { // f(New.map()); // Does not compile } } And an explanation:
Type inference doesn’t work for anything other than assignment. If you pass through the method of a new method, it will make it possible. This is a variable of type Object.
Nevertheless, I reproduced this code in the IDE, it was successfully compiled and launched. Is this a bug or is the information in the book out of date? I have jdk 8.