关于回调理解

来源:互联网 发布:linux 完全卸载mysql 编辑:程序博客网 时间:2024/06/08 15:02

1.回调分为回调跟异步回调

1.1回调

public class Me {public static void main(String[] args){People people=new People();people.goHome(new Car() {@Overridepublic void start(){System.out.println("The car has started.........");    1}});}}

public interface Car {public void start();}


public class People {public void goHome(Car car){car.start();                                                                         2System.out.println("Go home now!");                              3}}

dbug一下就知道代码执行路径是2---->1----->3


1.2异步回调

如ajax,新建线程去跑程序,如阻塞队列,发起请求不等相应继续往下执行,主线程不会去等待

0 0
原创粉丝点击