Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.lang.reflect

Interface InvocationHandler

java.lang.Object
|
+--java.lang.reflect.InvocationHandler


public interface InvocationHandler

This interface defines an invocation handler. Suppose you are using reflection, and found a method that requires that its parameter be an object of a given interface. You want to call this method, but have no idea what classes implement that interface. So, you can create a Proxy instance, a convenient way to dynamically generate a class that meets all the necessary properties of that interface. But in order for the proxy instance to do any good, it needs to know what to do when interface methods are invoked! So, this interface is basically a cool wrapper that provides runtime code generation needed by proxy instances.

While this interface was designed for use by Proxy, it will also work on any object in general.

Hints for implementing this class:

For a fun time, create an InvocationHandler that handles the methods of a proxy instance of the InvocationHandler interface!

Since:Author:See Also:

Method Summary

java.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)

When a method is invoked on a proxy instance, it is wrapped and this method is called instead, so that you may decide at runtime how the original method should behave.

Method Details

invoke

public Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)

When a method is invoked on a proxy instance, it is wrapped and this method is called instead, so that you may decide at runtime how the original method should behave. NullPointerException. In all remaining cases, if the returned object is not assignment compatible to the declared type of the original method, the proxy instance will generate a ClassCastException.

Parameters:

Returns:

Throws:

See Also: