Give example of APIs in Java which uses Proxy pattern?
Answered
Give example of APIs in Java which uses Proxy pattern?
Best answer
There is a built-in support for proxy pattern from JDK 1.3 onwards. The classes java.lang.reflect.Proxy and java.lang.reflect.InvocationHandler introduced in JDK 1.3 directly supports proxy pattern.
Proxy provides static methods for creating dynamic proxy classes and instances. InvocationHandler is an interface that has a single invoke(Object proxy, Method method, Object[] args) method. This method is implemented by the invocation handler of a proxy instance. Each proxy instance has an associated invocation handler. When a method is invoked on a proxy instance, the method invocation is encoded and dispatched to the invoke method of its invocation handler.