2011-02-17 78 views
4

我想知道在创建动态代理实例时何时调用newProxyInstance方法,ClassLoader参数究竟是什么?动态代理 - 创建新代理实例时的类加载器参数

public static Object newProxyInstance(ClassLoader loader, Class<?>[] interfaces, InvocationHandler h) throws IllegalArgumentException 

非常感谢!

P.S.我不确定如何正确使用代码格式标记。

回答

2

newProxyInstance文档定义了它的使用等同于:

Proxy.getProxyClass(loader, interfaces). 
    getConstructor(new Class[] { InvocationHandler.class }). 
    newInstance(new Object[] { handler }); 

所以,如果你想稍微详细地了解loader,你可以看一下文档getProxyClass。基本上,它只是用作定义生成的代理类的类加载器。

+0

感谢您的信息 – Joeblackdev 2011-02-18 10:10:59