使用接口
也就是使用多态来实现回调函数
interface ICallback{
void func(); //函数指针
}
class ClassWithCallbackFunction implements ICallback{
void func(){
实现..
}
}
class caller{
ICallback callback;
public doCallback(){
callback.func();
}
setCallback(ICallback callback){
this.callback = callback;
}
}
Caller caller = new Caller();
caller.setCallback(new ClassWithCallbackFunction());
也就是使用多态来实现回调函数
interface ICallback{
void func(); //函数指针
}
class ClassWithCallbackFunction implements ICallback{
void func(){
实现..
}
}
class caller{
ICallback callback;
public doCallback(){
callback.func();
}
setCallback(ICallback callback){
this.callback = callback;
}
}
Caller caller = new Caller();
caller.setCallback(new ClassWithCallbackFunction());