jdk动态代理

package com.gobaio.dynamicproxy.proxyCglib;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;

/**
 * @author fucong
 * @date 2019/8/11 21:00
 * @description jdk的动态代理
 */
public class Client {
    public static void main(String[] args) {
        Producer producer = new Producer();

        Producer producer1 =  (Producer)Enhancer.create(producer.getClass(),
                (MethodInterceptor) (proxy, method, objects, methodProxy) -> {
            Object returnValue = null;
            Float arg = (Float) objects[0];
            if ("salesProducts".equals(method.getName())) {
                returnValue = method.invoke(producer, arg * 0.8f);
            }
            return returnValue;
        });

        producer1.salesProducts(15000f);
    }
}

你可能感兴趣的:(jdk动态代理)