动态代理 - 创建新代理实例时的类加载器参数

时间:2011-02-17 18:49:21

标签: java dynamic-proxy

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

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

非常感谢!

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

1 个答案:

答案 0 :(得分:3)

newProxyInstance的文档将其用法定义为:

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

因此,如果您想了解loader的更多详情,可以查看getProxyClass的文档。基本上,它只是作为定义生成的代理类的类加载器。