-
Bug
-
Resolution: Unresolved
-
P4
-
8, 9, 10, 11
-
x86_64
-
generic
FULL PRODUCT VERSION :
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.16299.248]
A DESCRIPTION OF THE PROBLEM :
If a user mistakely invokes CompletionStage.thenApply() with a Supplier instead of with a Function then the compiler gives a misleading error message.
Given:
CompletionStage.thenApply(() -> methodThatReturnsCompletionStage())
I get:
method thenApply in interface java.util.concurrent.CompletionStage<T> cannot be applied to given types;
required: java.util.function.Function<? super java.util.Map<com.holdmyspot.pyramid.exchange.Currency,java.math.BigDecimal>,? extends U>
found: ()->string[...]coin)
reason: cannot infer type-variable(s) U
(argument mismatch; incompatible parameter types in lambda expression)
The problem has nothing to do with type-parameter U, but rather it is type-parameter T that has to be changed. Instead of:
CompletionStage.thenApply(() -> methodThatReturnsCompletionStage())
the code should read:
CompletionStage.thenApply(ignored -> methodThatReturnsCompletionStage())
Please improve this error message.
REPRODUCIBILITY :
This bug can be reproduced always.
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.16299.248]
A DESCRIPTION OF THE PROBLEM :
If a user mistakely invokes CompletionStage.thenApply() with a Supplier instead of with a Function then the compiler gives a misleading error message.
Given:
CompletionStage.thenApply(() -> methodThatReturnsCompletionStage())
I get:
method thenApply in interface java.util.concurrent.CompletionStage<T> cannot be applied to given types;
required: java.util.function.Function<? super java.util.Map<com.holdmyspot.pyramid.exchange.Currency,java.math.BigDecimal>,? extends U>
found: ()->string[...]coin)
reason: cannot infer type-variable(s) U
(argument mismatch; incompatible parameter types in lambda expression)
The problem has nothing to do with type-parameter U, but rather it is type-parameter T that has to be changed. Instead of:
CompletionStage.thenApply(() -> methodThatReturnsCompletionStage())
the code should read:
CompletionStage.thenApply(ignored -> methodThatReturnsCompletionStage())
Please improve this error message.
REPRODUCIBILITY :
This bug can be reproduced always.