Reputation: 13954
Excerpt from "Thinking in Java" book:
One of the complaints about generics is that it adds even more text to your code. Consider this :
Map<Person, List<? extends Pet>> petPeople = new HashMap<Person, List<? extends Pet>>();
It appears that you are repeating yourself, and that the compiler should figure out one of the generic argument lists from the other. Alas, it cannot, ...
Does this mean that the explicit type specification on the both sides is mandated by the compiler?
On the contrary, it seems to be working fine for me (without being explicit):
Map<Person, List<? extends Pet>> petPeople = new HashMap();
Upvotes: 0
Views: 39
Reputation: 120968
Your reading an ancient book copy, it works just fine since Java-7 and the addition of the diamond operator:
Map<Person, List<? extends Pet>> petPeople = new HashMap<>();
Upvotes: 4