JDK动态代理

public class JDKProxy2 implements InvocationHandler {

    private Object targetObject;

    public Object JDKProxy2(Object targetObject) {
        this.targetObject = targetObject;
        return Proxy.newProxyInstance(targetObject.getClass().getClassLoader(),
                targetObject.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("1");
        Object obj = method.invoke(targetObject, args);
        System.out.println("2");
        return obj;
    }

}

 

posted @ 2013-08-30 00:25  谷文仁  阅读(158)  评论(0编辑  收藏  举报