package customutil.proxy.dynamicProxy; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; /** * @author EBU7-dev1-ayh * @create 2021/11/25 0025 12:53 */ public class Test { public static void main(String[] args) { Customer customer = new Customer(); IOrderInterface iOrderInterface = (IOrderInterface) Proxy.newProxyInstance( customer.getClass().getClassLoader(), customer.getClass().getInterfaces(), new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object result = method.invoke(customer,args); System.out.println("接收到订单,正在去取餐途中。。。"); return result; } }); String result = iOrderInterface.order("鱼香肉丝"); System.out.println(result); } }