Program
If you need to create a class that implements a given set of interfaces at run time, and note that this class was created at runtime, you need to use the proxy class in Java to achieve your requirements.
The proxy class provides the ability to create classes at run time, and the new class implements the interface you specify. Of course, you cannot define new code for the methods in the interface to implement at run time, but instead provide a call processor to implement. The calling processor is an object of the class that implements the Invocationhandler interface, and this interface has only one method:
Object Invoke (Object Proxy,method mtd,object[] args)
Where proxy is the proxy object, MTD is the object of the class that describes the method, which executes its invoke (object obj,object[] args) method to invoke the method encapsulated in the Mthod object; args is an array of the method arguments stored.
To establish a proxy object: Use the Newproxyinstance method of the proxy class, in the following format:
Object proxy=proxy.newproxyinstance (Null,interfaces,handler);
Where the first parameter is a class loader, this uses the default loader, represented by NULL, and the second parameter is an array of class, each of which is an interface, which is used to specify the set of interfaces to implement, even if only one interface is passed through an array, and the third parameter is the calling processor.
When a method is invoked on a proxy object, the Invoke method of the calling processor is automatically invoked, the method and parameter being invoked are automatically passed to the Jmtdt args form parameter of the Inboke method, and the method specified in the MTD object is invoked with the arguments in the args parameter array.
Agent Application: Method invocation Tracking (wrapping objects to be tracked into proxy class objects); Providing routes for remote invocation methods; User interface events are associated with actions (similar functionality in C #).