jvm中分配Dispatch的概念 分派是针对方法而言的,指的是方法确定的过程,通常发生在方法调用的过程中.分派根据方法选择的发生时机可以分为静态分派和动态分派,其中对于动态分派,根据宗量种数又可以分为单分派和多分派.实际上指的是方法的接收者和属性的所有者的类型确定(determine by atual type or determine by static type).根据类型确定发生在运行期还是编译期以及依据实际类型还是静态类型,可以将Dispatch分为动态分配Dynamic Dispat
/** * 接口应用 */ public class Main { public static void main(String[] args) { Person p = new Person("fish7"); p.setIsay(new BeforeGong()); p.say(); p.setIsay(new AfterGong()); p.say(); } } class Person{ //只有在运行期才和say行为关联起来,这就叫面向接口编程 private String
举例子: package test_instance; public class TestClassLoaderTime { public TestClassLoaderTime(){ System.out.println("构造器执行"); } { System.out.println("静态代码块执行"); } static Demo2 demo2 = new Demo2(); private Demo3 demo3 = new Demo3(); public