Skip to content

Instantly share code, notes, and snippets.

@natp0ng
Created January 23, 2013 04:32
Show Gist options
  • Save natp0ng/4601953 to your computer and use it in GitHub Desktop.
Save natp0ng/4601953 to your computer and use it in GitHub Desktop.
Callback in class
// The callback interface
interface MyCallback {
void callbackCall();
}
// The class that takes the callback
class Worker {
MyCallback callback;
void onEvent() {
callback.callbackCall();
}
}
// Option 1:
class Callback implements MyCallback {
void callbackCall() {
// callback code goes here
}
}
worker.callback = new Callback();
// Option 2:
worker.callback = new MyCallback() {
void callbackCall() {
// callback code goes here
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment