Both the proxy and the target share this common interface. Then, the proxy delegates
the calls to the target class.
JDK Proxy Class
JDK provides both the class Proxy and the interface InvocationHandler in the
java.lang.reflect package, since version 1.3. Using JDK Proxy classes, you can
create your own classes implementing multiple interfaces of your choice, at run time.
Proxy is the super class for any dynamic proxy instances you create at run time.
Moreover, the Proxy class also accommodates a host of static methods which will
help you to create your proxy instances. getProxyClass and newProxyInstance are
two such utility methods.
The Proxy API is listed in the following in brevity:
package java.lang.reflect;
public class Proxy implements java.io.Serializable
{
protected InvocationHandler h;
protected Proxy(InvocationHandler h);
public static InvocationHandler getInvocationHandler(Object proxy)
throws IllegalArgumentException;
public static Class> getProxyClass(ClassLoader loader,
Class>... interfaces)
throws IllegalArgumentException;
public static boolean isProxyClass(Class> cl);
public static Object newProxyInstance(ClassLoader loader,
Class>[] interfaces, InvocationHandler h)
throws IllegalArgumentException
}
In the above code, you can invoke the Proxy.
Pages:
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332