...
Code Block |
---|
public interface CallBack { void callMethod(); } class MyCallBack implements CallBack { public void callMethod() { System.out.println("CallBack invoked"); } } class Client { CallBack callback; public void registerCallBack(CallBack callback) { this.callback = callback; } public void doSomething() { callback.callMethod(); } public static void main(String[] args) { Client client = new Client(); CallBack myCallBack = client.registerCallBack(new MyCallBack(); client.registerCallBack( myCallBack); // ... client.doSomething(); // prints "CallBack invoked" } } |
...