标签:
1. 定义一个回调接口
public interface CallBack { //执行回调操作的方法 void execute(); }
public class Test { /** * 测试函数,通过定义CallBack接口的execute方法 * @param callBack */ public void test(CallBack callBack) { System.out.println("回调前。。。"); callBack.execute(); ///进行回调操作 System.out.println("回调后。。。"); } }
public class Snippet { public static void main(String[] args) { Test test = new Test(); test.test(new CallBack() { // 重写 execute 方法 public void execute() { System.out.println("我被调用了。"); } }); } }
4. 结果
回调前。。。
我被调用了。
回调后。。。
以上。
参考资料
http://blog.csdn.net/shimiso/article/details/8560640
标签:
原文地址:http://my.oschina.net/wangbiglei/blog/498343