Created
April 25, 2012 09:15
-
-
Save firexel/2488421 to your computer and use it in GitHub Desktop.
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 interface CallbackInterface { | |
void onSomethingHappens(int data); | |
void onAnotherThingHappens(); | |
} | |
public class CallbackHost { | |
private CallbackInterface callback; | |
public CallbackHost(CallbackInterface callback) { | |
this.callback = callback; | |
} | |
public void setSomeData(int data) { | |
if (callback != null) | |
callback.onSomethingHappens(42); | |
} | |
} | |
public class CallbackClient { | |
public CallbackClient() { | |
CallbackHost host = new CallbackHost(new CallbackInterface() { | |
public void onSomethingHappens(int data) { | |
System.out.println(data); | |
} | |
public void onAnotherThingHappens() { | |
System.out.println("AnotherThingHappens"); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment