开发者

Dynamic Proxy - Class Loader parameter when creating a new proxy instance

开发者 https://www.devze.com 2023-02-11 23:31 出处:网络
I was wondering about when you call the newProxyInstance method when creating a dynamic proxy instance, what exactly is the ClassLoader argument for?

I was wondering about when you call the newProxyInstance method when creating a dynamic proxy instance, what exactly is the ClassLoader argument for?

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

Many thanks!

P.S. I'm not sure how to use the code formatting tag开发者_StackOverflow社区s correctly.


The documentation for newProxyInstance defines its use to be equivalent to:

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

So, if you want a bit more detail about loader, you can look at the documentation for getProxyClass. Basically, it just serves as the class loader that defines the generated proxy class.

0

精彩评论

暂无评论...
验证码 换一张
取 消