如果我在服务中有两个boolean
方法,我怎样才能确保onSuccess
方法处理返回boolean
的正确方法?
例如,在onSuccess
方法中我说:
if (result instanceof 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
答案 0 :(得分:3)
有很多灰色区域,但请耐心等待: 在SomethingRPCService.java中
boolean isA();
boolean isB();
在SomethingRPCServiceAsync.java中
void isA(AsyncCallback<Boolean> callback);
void isB(AsyncCallback<Boolean> callback);
在您的活动中
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
}
});
你可以(必须?)实际输入你的回报
编辑:用你的例子,我可以看到更好一点;你的回调不应该是相同的,你应该覆盖它,所以代码不一样,因为它不是