Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass Java Callback Function to JSNI Method?

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) {
     [email protected]::onSuccess(Ljava/lang/String;)("success!");
  });

}-*/;

}
like image 981
confile Avatar asked Mar 21 '23 10:03

confile


1 Answers

You can call the callback methods in this way:

native void test(Callback<String, String> callback) /*-{
  [email protected]::onSuccess(Ljava/lang/Object;)("success!");
}-*/;
like image 113
Fedy2 Avatar answered Apr 02 '23 09:04

Fedy2