0

In my code I am trying to pass a function as a parameter.

The function has two arguments: a promise, and an int. I want to pass the promise with the parameter, and the int will be set by the child function.

public void getUser(final Promise promise) {

    UserHelper.saveMe(getReactApplicationContext(), callBack(promise, int myInt));

}

public void callBack(Promise promise, int myInt){
    if (user != null) {
        promise.resolve(doSomething(myInt));
    }
}

Child Function

public static void saveMe(Context context, function callBack) {

    **some code here

    returnUser(20);

}

I have done similar things in JS and PHP before, but I can't figure out how to run in Java.

Thanks for your help.

fractal5
  • 2,034
  • 4
  • 29
  • 50
  • you can't pass a method (not function) in Java. For alternative, read https://stackoverflow.com/questions/2186931/java-pass-method-as-parameter – ישו אוהב אותך Nov 08 '17 at 02:31
  • Is there any way to implement this without using an interface? I mean having the promise executed when the child function is complete? I tried passing the promise as a parameter, but the app crashes when it gets to that point. – fractal5 Nov 08 '17 at 14:15

0 Answers0