InvocationHandler


InvocationHandler java.lang.reflect

Java 1.3

This interface defines a single invoke( ) method that is called whenever a method is invoked on a dynamically created Proxy object. Every Proxy object has an associated InvocationHandler object that is specified when the Proxy is instantiated . All method invocations on the proxy object are translated into calls to the invoke( ) method of the InvocationHandler .

The first argument to invoke( ) is the Proxy object through which the method was invoked. The second argument is a Method object that represents the method that was invoked. Call the geTDeclaringClass( ) method of this Method object to determine the interface in which the method was declared. This may be a superinterface of one of the specified interfaces or even java.lang.Object when the method invoked is toString( ) , hashCode( ) , or one of the other Object methods . The third argument to invoke( ) is the array of method arguments. Any primitive type arguments are wrapped in their corresponding object wrappers (e.g., Boolean , Integer , Double ).

The value returned by invoke( ) becomes the return value of the proxy object method invocation and must be of an appropriate type. If the proxy object method returns a primitive type, invoke( ) should return an instance of the corresponding wrapper class. invoke( ) can throw any unchecked (i.e., runtime) exceptions or any checked exceptions declared by the proxy object method. If invoke( ) throws a checked exception that is not declared by the proxy object, that exception is wrapped within an unchecked UndeclaredThrowableException that is thrown in its place.

 public interface  InvocationHandler  {  // Public Instance Methods  Object  invoke  (Object  proxy  , Method  method  , Object[ ]  args  ) throws Throwable;   } 

Passed To

java.lang.reflect.Proxy.{newProxyInstance( ) , Proxy( )}

Returned By

java.lang.reflect.Proxy.getInvocationHandler( )

Type Of

java.lang.reflect.Proxy.h



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net