定义接口
package com.zhengqing.demo.canal.mytest.huidiaohanshu;
public interface CallBack {
//执行回调操作的方法
void execute(Integer a);
}
具体使用方法
package com.zhengqing.demo.canal.mytest.huidiaohanshu;
/**
* @author cyh
* @Description
* @date 2022/3/15 14:03
*/
public class Test1 {
public static void testMethod(Integer a, CallBack callBack){
callBack.execute(a);
}
/**
* 原因:testMethod方法的具体逻辑实现我不确定,通过回调的方式来做自定义实现,
* 此处我只需要传递给testMethod方法参数就行,通过回调函数去执行具体逻辑
* @param args
*/
public static void main(String[] args) {
Test1.testMethod(1, new CallBack() {
@Override
public void execute(Integer a) {
System.out.println(a);
}
});
}
}