标签:ade lib span cat info ring nbsp png color
interface HelloInterface { String sayHello(); } class Hello implements HelloInterface{ @Override public String sayHello() { System.out.println("Hello zhanghao!"); return "Hello"; } } class ProxyHandler implements InvocationHandler { private Object object; public ProxyHandler(Object object){ this.object = object; } @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { System.out.println("Before invoke " + method.getName()); Object value = method.invoke(object, args); System.out.println("After invoke " + method.getName()); return value; } } public class proxyTest { public static void main(String[] args) { HelloInterface hello = new Hello(); InvocationHandler handler = new ProxyHandler(hello); HelloInterface proxyHello = (HelloInterface) Proxy.newProxyInstance(hello.getClass().getClassLoader(), hello.getClass().getInterfaces(), handler); Object value = proxyHello.sayHello(); System.out.println(value); }
标签:ade lib span cat info ring nbsp png color
原文地址:https://www.cnblogs.com/superxuezhazha/p/12358437.html