标签:
package test; class ProxyTest { public static void main(String[] args) { ProxyClass proxy = new ProxyClass(); proxy.method_1(); /* Console: This is ProxyClass.method_1() ---Before--- This is RelClass.method_1() ---After---- */ } } class ProxyClass implements RelClassInf { RelClass rel = new RelClass(); @Override public void method_1() { System.out.println("This is ProxyClass.method_1()"); System.out.println("---Before---"); rel.method_1(); System.out.println("---After----"); } @Override public void method_2() { System.out.println("This is ProxyClass.method_2()"); System.out.println("---Before---"); rel.method_2(); System.out.println("---After----"); } } interface RelClassInf { void method_1(); void method_2(); } class RelClass implements RelClassInf { @Override public void method_1() { System.out.println("This is RelClass.method_1()"); } @Override public void method_2() { System.out.println("This is RelClass.method_2()"); } }
标签:
原文地址:http://www.cnblogs.com/15ho/p/5821406.html