You should be utilizing that T
(the type parameter) -
private <T extends Foo> Map<Integer, T> createMap(List<T> foos) {
Map<Integer, T> map = new LinkedHashMap<Integer, T>();
for (T foo : foos) {
When you do that your generic method returns Map<Integer, Bar>
, with the help of type inference, instead of Map<Integer, Foo>
.