What are proxies for Java?

I read the Proxies section in the famous Horstmann Core Java book. But I am new to this concept. As it is written in the book, proxy servers are necessary only when you do not yet know at compile time which interfaces you need to implement. However, when you create a proxy object, you need to provide an array of class objects that are just the interfaces that will be implemented. Doesn't that sound like self-contradiction? Please light me up. Thank!

+3
source share
1 answer

No, there is no contradiction.

, , , .. . , Class String. , (, Spring ) .

Proxy javadoc:

String className = readClassNameFromFile(); 
Class<?> myClass = Class.forName(className);
Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(),
                                          new Class[] { myClass },
                                          handler);
0

All Articles