我正在学习动态代理。但我不知道为什么参数dao不需要'final'来装饰。这是我定义的ProxyFactory类。
private IUserDao dao;
public void setDao(IUserDao dao) {
this.dao = dao;
}
public Object getProxyInstance(){
return Proxy.newProxyInstance(
dao.getClass().getClassLoader(),
dao.getClass().getInterfaces(),
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("begin......");
System.out.println(proxy.getClass());
Object result = method.invoke(dao, args);
System.out.println("end......");
return result;
}
});
}