It’s the type inference that doesn’t get it right. If you provide the type argument explicitly it works as expected:
List<? extends Number> wildCardList = Arrays.asList(1, 2, 3D);
wildCardList.stream().collect(Collectors.<Number, Integer, Number>toMap(
number -> Integer.valueOf(number.intValue()),
number -> number));
This is a known javac bug: Inference should not map capture variables to their upper bounds. The status, according to Maurizio Cimadamore,
a fix was attempted then backed out as it was breaking cases in 8, so we went for a more conservative fix in 8 while doing the full thing in 9
Apparently the fix has not yet been pushed. (Thanks to
Joel Borggrén-Franck for pointing me in the right direction.)