package cglibDynamicProxy.demo02;

import java.lang.reflect.Method;

/**
 * @author WanJl
 * @version 1.0
 * @title MyTest
 * @description
 * @create 2025/8/7
 */
public class MyTest {
    public static void main(String[] args) throws Exception{
        User user =new User();
        //创建代理对象GetterSetterProxy
        GetterSetterProxy proxy=new GetterSetterProxy();
        User userProxy = (User) proxy.createProxy(user);

        //通过代理对象给User对象设置属性值
        Method setName = userProxy.getClass().getMethod("setName", String.class);
        setName.invoke(userProxy,"张三");

        Method setAge = userProxy.getClass().getMethod("setAge", int.class);
        setAge.invoke(userProxy,25);

        //通过代理对象获取属性值
        Method getName = userProxy.getClass().getMethod("getName");
        System.out.println("姓名："+getName.invoke(userProxy));
        Method getAge = userProxy.getClass().getMethod("getAge");
        System.out.println("年龄："+getAge.invoke(userProxy));



    }
}
