[英]F.Promise - cyclic inference
At first, i tried to cast with Result 一开始,我尝试使用Result进行投射
(Result) deleteDummy().
it will compaint you can't cast. 它将使您无法投射。
But when i change to ok(), it say cyclic inference 但是当我更改为ok()时,它说循环推断
I'm getting a bit confuse here. 我在这里有点困惑。 It keeps saying cyclic inference. 它一直说循环推断。 It seems like the return not compatible.... any help? 看来退货不兼容...。有什么帮助吗?
public class Delete_Dummy {
public static F.Promise<Result> delete() {
F.Promise<Boolean> promise = isDummyThere(); //rest call to check the exist of the dummy
return promise.map(aBoolean ->
{
if(!aBoolean) {
return badRequest("No..i'm not there");
}
return deleteDummy().map(result-> ok()); //<=cyclic inference <<<<
});
}
private static F.Promise<Result> deleteDummy() {
String url = "some url";
return WS.url(url)
.delete()
.map(response -> {
if (response.getStatus() == NO_CONTENT) {
return ok("OK..deleted");
}
return badRequest("you are bad.");
} // end of Function<WS>
);
}
}
I'm not sure why it would say "cyclic inference", but badRequest()
seems to have the type Result
while deleteDummy().map(result-> ok())
does have the type Promise<Result>
. 我不确定为什么会说“循环推断”,但是badRequest()
似乎具有Result
类型,而deleteDummy().map(result-> ok())
确实具有Promise<Result>
类型。 They are not compatible with each other. 它们彼此不兼容。
If you have a callback that results itself in a promised result, you will have to use flatMap
. 如果您有一个回调,该回调本身会产生承诺的结果,则必须使用flatMap
。 You can combine it with a non-promise value in your if-else by using pure
: 您可以通过使用pure
将它与if-else中的非承诺值组合:
public static F.Promise<Result> delete() {
F.Promise<Boolean> promise = isDummyThere(); //rest call to check the exist of the dummy
return promise.flatMap(aBoolean -> {
if (!aBoolean) {
return F.Promise.pure(badRequest("No..i'm not there"));
}
return deleteDummy().map(result-> ok());
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.