Skip to content

Instantly share code, notes, and snippets.

@DavidSanf0rd
Last active June 21, 2017 13:22
Show Gist options
  • Save DavidSanf0rd/88ad54913d16b8dc481f5d9ee644dead to your computer and use it in GitHub Desktop.
Save DavidSanf0rd/88ad54913d16b8dc481f5d9ee644dead to your computer and use it in GitHub Desktop.
Java completion handler
/**
* Created by sanf0rd on 21/06/17.
*/
public class Main {
public static void main(String[] args) {
Wrapper wrapper = new Wrapper();
wrapper.doStuff(result -> System.out.println(result));
}
}
interface MyListener {
void onCompletion(String any);
}
public class Wrapper {
public void doStuff(MyListener listener) {
//make the assync call, you might need to save the listener's state in a field.
String result = "Now i have the result";
listener.onCompletion(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment