当需要在方法前后做一些操作就需要借助动态代理来实现 jdk实现代理是被代理类实现接口的方式 public interface UserInterface { void test(); } public class UserService implements UserInterface { public void test() { System.out.println("call test method"); } } UserService target = new UserService(); Object o = Proxy.newProxyInstance(Test.class.getClassLoader(), new Class[]{UserInterface.class}, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { System.out.println("test...
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile