Pass Java Callback Function to JSNI Method?

怎甘沉沦 提交于 2019-12-21 21:15:53

问题


I want to pass a success and a failure callback Java function to a JSNI method.

This is what I get so far but it does not work. How can I fix it?

package c;

public class A {

test(new Callback<String, String>() {

    @Override
    public void onFailure(String reason) {
        Window.alert("fail");
    }

    @Override
    public void onSuccess(String result) {
        Window.alert("suc");
    }
});


native void test(Callback<String, String> callback) /*-{

  var callback = $entry(function(event) {
     callback.@c.A.Callback::onSuccess(Ljava/lang/String;)("success!");
  });

}-*/;

}

回答1:


You can call the callback methods in this way:

native void test(Callback<String, String> callback) /*-{
  callback.@com.google.gwt.core.client.Callback::onSuccess(Ljava/lang/Object;)("success!");
}-*/;


来源:https://stackoverflow.com/questions/20407957/pass-java-callback-function-to-jsni-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!