The following code does not compile with my JDK14:
Map<Integer, String> map = Arrays.asList("this", "is", "just", "an", "example").stream()
.collect(Collectors.toMap(w -> w.length(),
w -> w,
(existing, replacement) -> replacement,
() -> new TreeMap<>(Comparator.reverseOrder())));
while if I specify the types for the constructor of the TreeMap it works fine:
Map<Integer, String> map4 = Arrays.asList("this", "is", "just", "an", "example").stream()
.collect(Collectors.toMap(w -> w.length(),
w -> w,
(existing, replacement) -> replacement,
() -> new TreeMap<Integer, String>(Comparator.reverseOrder())));
Am I missing something or is there a bug in the type erasure system of JDK14?