public interface UserService {
void add();
}
public class UserServiceImpl implements UserService {
@Override
public void add() {
System.out.print("add");
}
}
public class StaticProxy implements UserService {
UserService userService;
public StaticProxy(UserServiceImpl userService){
this.userService=userService;
}
@Override
public void add() {
System.out.println("这是代理类做的事");
userService.add();
System.out.println("这是代理类做的事");
}
}
根据上边的静态代理,运用Java的反射,如何实现动态代理?