22 public void doBefore(){
23 System.out.println(“do before”);
24 }
25
26 public void doAfter(){
27 System.out.println(“do after”);
28 }
29 }
4.测试类:
01 package test.dynamicproxy;
02
03 import java.lang.reflect.Proxy;
04
05 public class TestDynamicProxy {
06
07 /**
08 * @param args
09 */
10 public static void main(String[] args) {
11 Target t=new Target();
12 TargetInvocationHandler handler=new TargetInvocationHandler(t);
13
14 TargetInterface proxy = (TargetInterface) Proxy.newProxyInstance(
15 t.getClass().getClassLoader(),
16 t.getClass().getInterfaces(),
17 handler);
18
19 proxy.SayHello();
20
21 int b=proxy.sum(10,20);
22 System.out.println(b);
23 }
24
25 }