1 源码解析
1.1 源码解析1(jdk中的应用)
1.2 源码解析2(spring中的应用)
1.3 源码解析3(mybaties中的应用)
1 源码解析
1.1 源码解析1(jdk中的应用)
java.lang.reflect.Proxy
public class Proxy implements java.io.Serializable { protected Proxy(InvocationHandler h) { doNewInstanceCheck(); this.h = h; }
//此处产生一个新的实例(目标对象) public static Object newProxyInstance(ClassLoader loader, Class<?>[] interfaces, InvocationHandler h) throws IllegalArgumentException { if (h == null) { throw new NullPointerException(); } final Class<?>[] intfs = interfaces.clone(); final SecurityManager sm = System.getSecurityManager(); if (sm != null) { checkProxyAccess(Reflection.getCallerClass(), loader, intfs); } /* * Look up or generate the designated proxy class. */ Class<?> cl = getProxyClass0(loader, intfs); /* * Invoke its constructor with the designated invocation handler. */ try { final Constructor<?> cons = cl.getConstructor(constructorParams); final InvocationHandler ih = h; if (sm != null && ProxyAccessHelper.needsNewInstanceCheck(cl)) { // create proxy instance with doPrivilege as the proxy class may // implement non-public interfaces that requires a special permission return AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { return newInstance(cons, ih); } }); } else { return newInstance(cons, ih); } } catch (NoSuchMethodException e) { throw new InternalError(e.toString()); } } }
1.2 源码解析2(spring中的应用)
1.3 源码解析3(mybaties中的应用)