回调就像23种经典设计模式一样,也是一种通用的模式,每种语言都可以实现该模式,只不过所采取的方法不一样罢了!C和C++是通过“函数指针”来调用处理方法的,而在Java的面向对象模型中,不支持这种方法,因而看起来好像排除了使用这种比较舒服的机制,但事实并非如此。
public void callbackMethod();
public class A implements CallBack{
}
public void callbackMethod(){
System.out.println("callbackMethod is executing!");
}
public void doSomething(CallBack cb){
System.out.println(“I am processing my affairs… ”);
cb.callbackMethod();
}