0

I'm learning dynamic proxy.But I don't know why the parameter dao need no 'final' to decorate.Here is the ProxyFactory Class I defined.

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;
                }
            });
}
  • @Berger Could you please explain me why do you think those questions are the same? – freedev Mar 23 '17 at 09:31
  • I thought the field dao can not be used in an Anonymous Inner Class unless 'final' with it..?Confused with these concepts. – Lenheim Mar 24 '17 at 01:19

0 Answers0