It is not possible to derive a type argument for the map <R> (function <? Super T ,? extends R>) in some specific situation
I have the following classes in my Sandbox.java file:
package sandbox; import java.util.Arrays; import java.util.Collection; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.stream.Collectors; public class Sandbox { public static void main(String[] args) throws Exception { ExecutorService executor = Executors.newSingleThreadExecutor(); Collection<String> s = Arrays.asList(1,2,4,100).stream() .map(i -> CompletableFuture .supplyAsync(() -> Wrapper.of(i), executor) .thenApply(d -> d.get().toString()) ) .map(CompletableFuture::join) .collect(Collectors.toList()); executor.shutdown(); System.out.println(s); } } class Wrapper<T> { T t; private Wrapper(T t) { this.t = t; } public T get() { return t; } public static <T> Wrapper<T> of (T t) { return new Wrapper<>(t); } } compilation in Eclipse shows an error on line 14 "It is not possible to derive a type argument for a map (function)."
The same code compiles without problems using pure javac (JDK 1.8.0_121).
If I change the correct line to:
Collection<String> s = Arrays.asList(1,2,4,100).stream() .map(i -> CompletableFuture .supplyAsync(() -> Wrapper.of(i), executor) .<String>thenApply(d -> d.get().toString()) ) .map(CompletableFuture::join) .collect(Collectors.toList()); then the code compiles without errors in Eclipse.
Does anyone know why this behavior exists? This is mistake?
I am using Eclipse 4.6.2.20161208-0625 (it does not find updates at the moment).
+5
2 answers
I confirmed that this is a bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=512486 . It was declared as authorized in 4.6.3. I will confirm this when the stable version is available.
+3