2011-02-17 33 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