Consider the following 2 controllers written using Play Framework 2.3.8:
Java8 lambdas:
public static Promise<Result> testLambda() {
final Promise<Boolean> promiseBool = Promise.promise(() -> "TEST".equals("test"));
return promiseBool.map(bool -> ok()).recover(t -> badRequest());
}
"Normal":
public static Promise<Result> test() {
final Promise<Boolean> promiseBool = Promise.promise(new Function0<Boolean>() {
@Override
public Boolean apply() throws Throwable {
return "TEST".equals("test");
}
});
return promiseBool.map(new Function<Boolean, Result>() {
@Override
public Result apply(Boolean bool) throws Throwable {
return ok();
}
}).recover(new Function<Throwable, Result>() {
@Override
public Result apply(Throwable t) throws Throwable {
return badRequest();
}
});
}
The controller written using lambdas gives me this ERROR in eclipse: Type mismatch: cannot convert from F.Promise<Results.Status> to F.Promise<Result>
while the second one doesn't. This happens only when using the recover()
function.
On the other hand, sbt compiles the code without complaining.
Question: Why is this happening and how can it be fixed?
For others searching for a -> REASON:
Based on Salem's answer and this answer: This is an Eclipse bug and has nothing to do with type inference or other <insert you favourite Java bashing here>.