O'Reilly logo

Special Edition Using Java 2 Standard Edition by Geoff Friesen, Chuck Cavaness, Brian Keeton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing an Interface Using a Proxy

Java 1.3 added the capability to dynamically create a proxy class at runtime that implements one or more interfaces. The Proxy class and the InvocationHandler interface were added to the java.lang.reflect package to support this functionality. With this capability, you can create a proxy that delegates the method calls associated with the interfaces it implements to a class that implements InvocationHandler. This interface defines a single method:

public Object invoke(Object proxy, Method method, Object[] args)
  throws Throwable

You obtain a proxy to work with an InvocationHandler using a static method of the Proxy class:

 public static Object newProxyInstance(ClassLoader loader, Class[] interfaces, InvocationHandler ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required