Classes and interfaces that need to be used:
- Class: Proxy
- Interface: Invocationhandler
Invocationhandler:
- Interface method:
throws Throwable
- Method Parameters:
Object Proxy: Instance of the proxy invocation method: Method object[] args: An array of parameter objects when executing a method
- Return value: Returns the result of the proxy object's execution method
-
- You must implement Invocationhandler this interface
-
-
- JDK Comment (partial interception):
@param proxy the proxy instance that the method was invoked On@param Method the {@code method} instance corresponding to the interface method Invoked on the proxy instance. @param args an array of objects containing the values of the arguments passed in the Metho D invocation on the proxy instance, or {@code null } if interface method takes no arguments. @ return the value to from the method invocation on the proxy instance.
Proxy:
- The method to use:
Public Static Object newproxyinstance (ClassLoader loader, class<?>[] interfaces, invocationhandler h) throws illegalargumentexception
- Method Parameters:
The ClassLoader Loader:classloader object, which is used to load the generated proxy objectinto an array of Class <?> [] Interfaces:interface objects, Proxy object Implementation method Invocationhandler H:invocationhandler object, loaded with the specified loader, and implements a proxy instance of Invocationhandler for the specified interface
- Role: To get a dynamic proxy object
- JDK notes:
@param classclass@param forclass to Implement@param h the invocation handler to dispatch method invocations to@ return class class
implements the specified interfaces
Java Dynamic Agent mechanism