爱生活爱胖胖
import java.lang.reflect.InvocationHandler;import java.lang.reflect.Method;import java.lang.reflect.Proxy;public class HelloWorld{ public static void main(String []args){ final Dog dog = new Dog(); SingleMan man = (SingleMan) Proxy.newProxyInstance(SingleMan.class.getClassLoader(), new Class[]{SingleMan.class}, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Method m = dog.getClass().getMethod(method.getName(), method.getParameterTypes()); Object result = m.invoke(dog, args); return result; } }); man.say(); } public static class Dog { public void say() { System.out.println("汪!汪!"); } } public interface SingleMan { void say(); }}