我有一个场景,需要指定Synchrnous函数的返回类型,代码如下:
@RemoteServiceRelativePath("show_box")
public interface ShowBoxCommandService extends RemoteService{
public ArrayList<String> showBox();
}该方法在服务器上的实现为:
public ArrayList<String> showBox() {
ArrayList<String> box = new ArrayList<String>();
Iterator<Box> boxes = BoxRegistry.getInstance().getBoxes();
while (boxes.hasNext()) {
box.add(boxes.next().toString());
}
return box;
}我尝试在客户端以以下格式定义回调变量,以便调用该方法
AsyncCallback<Void> callback = new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
// TODO: Do something with errors.
// console was not started properly
}
@Override
public void onSuccess(Void result) {
// TODO Auto-generated method stub
// dialog saying that the console is started succesfully
}
};使用aync接口代码更新:
public interface ShowBoxCommandServiceAsync {
void showBox(AsyncCallback<ArrayList<String>> callback);
}但这会导致异步方法中的方法定义发生变化。
任何想法或线索都会有帮助。
谢谢,Bhavya
附言:如果这是重复的话,很抱歉。
发布于 2011-09-06 07:59:05
回调应该是:
AsyncCallback<ArrayList<String>> callback = new AsyncCallback<ArrayList<String>>() {
public void onFailure(Throwable caught) {
// TODO: Do something with errors.
// console was not started properly
}
@Override
public void onSuccess(ArrayList<String> result) {
// TODO Auto-generated method stub
// dialog saying that the console is started succesfully
}
};如果您不需要利用结果,那么您可以忽略它,但如果是这样的话,您可能应该质疑您的设计,以及为什么首先需要该方法来返回ArrayList<String>。
发布于 2011-08-31 15:22:35
如果服务接口如下所示:
public interface ShowBoxCommandService extends RemoteService {
public ArrayList<String> showBox();
}然后,您必须具有关联的异步接口:
public interface ShowBoxCommandServiceAsync {
public void showBox(AsyncCallback<ArrayList<String>> callback);
}这意味着,您应该传递给showBox的回调类型是AsyncCallback<ArrayList<String>>。
new AsyncCallback<ArrayList<String>>() {
@Override
public void onSuccess(ArrayList<String> list) {
// ...
}
@Override
public void onFailure(Throwable caught) {
// ...
}
}发布于 2011-08-31 15:18:01
哈?你的方法返回一个ArrayList,而你在你的调用中声明为空?
Change <Void> to <ArrayList<String>>https://stackoverflow.com/questions/7253703
复制相似问题