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

I was wondering 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 

Thank you very much!

PS I'm not sure how to use code formatting tags correctly.

+4
source share
1 answer

The documentation for newProxyInstance determines that its use is equivalent to:

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

So, if you want to get more detailed information about loader , you can see the documentation for getProxyClass . Essentially, it simply serves as a class loader, which defines the generated proxy class.

+2
source

Source: https://habr.com/ru/post/1340216/


All Articles