Last active
June 21, 2017 13:22
-
-
Save DavidSanf0rd/88ad54913d16b8dc481f5d9ee644dead to your computer and use it in GitHub Desktop.
Java completion handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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