gpt4 book ai didi

java - 在 GWT 异步回调中,如何在 onSuccess 中处理相同的返回类型?

转载 作者:行者123 更新时间:2023-12-01 19:55:14 25 4
gpt4 key购买 nike

如果我的服务中有两个 boolean 方法,如何确保 onSuccess 方法处理返回 boolean 的正确方法>?

例如,在 onSuccess 方法中我说:

if (result instanceof Boolean) {};

有没有办法可以区分返回 boolean 值的服务方法?否则,无法保证正确的代码将在我的 onSuccess 方法中执行,就好像结果是一个 boolean 值,如果调用我的两个 boolean 值服务方法中的任何一个,它将执行。

这是我面临的问题的示例:

private class DefaultCallback implements AsyncCallback
{
@Override
public void onFailure(Throwable caught)
{
mainGUI.getServerResponseLabel().setStyleName("serverResponseLabelError");
mainGUI.getServerResponseLabel().setHTML("An error occurred while "
+ "attempting to contact the server. Please check your network " + "connection and try again.");
}

@Override
public void onSuccess(Object result)
{
if (result instanceof Boolean)
{
//
I have two methods that return a boolean here,
so this block will execute no matter which one is called;
for one method I want to display a GUI windows saying "Upload complete",
and for another, create an excel spreadsheet. But the boolean value of one method won't be relevant to the other

最佳答案

有很多灰色地带,但请耐心等待:在 SomethingRPCService.java 中

boolean isA();
boolean isB();

在 SomethingRPCServiceAsync.java

void isA(AsyncCallback<Boolean> callback);
void isB(AsyncCallback<Boolean> callback);

在您的 Activity 中

somethingService.isA(new AsyncCallback<Boolean>() {
@Override
public void onSuccessImpl(final Boolean response) {
//will be executed on success of THIS call
}
@Override
public void onFailure(final Throwable caught) {
// not relevant here
}
});

somethingService.isB(new AsyncCallback<Boolean>() {
@Override
public void onSuccessImpl(final Boolean response) {
//will be executed on success of THIS call
}
@Override
public void onFailure(final Throwable caught) {
// not relevant here
}
});

您可以(必须?)实际输入您的返回单

编辑:有了你的例子,我可以看得更好一点;您的回调不应该相同,您应该覆盖它,以便代码不一样,因为它不一样

关于java - 在 GWT 异步回调中,如何在 onSuccess 中处理相同的返回类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49877019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com