This article wants to extend the Java dynamic proxy mechanism from the interface to the class, so that the class can enjoy the dynamic proxy support similar to the interface.
Design and characteristics
The newly extended class name, Proxyex, inherits directly from Java.lang.reflect.Proxy, and also declares a public static method with the same name as the original proxy class, in order to maintain the exact same use method as the original proxy mechanism.
Figure 1. Proxyex class inheritance Diagram
The biggest difference from the original proxy mechanism is that the dynamically generated proxy class will no longer inherit from the proxy class and inherit the class that needs to be represented. Because of the single inheritance principle of Java, the extension agent mechanism does not have more than one number of classes supported, but it can declare implementations of several interfaces. Package management mechanism is similar to the original, does not support more than one class and interface is not public at the same time, if there is only a non-public class or interface, assuming that its package is Packagea, the dynamically generated proxy class will be in the package packagea; The generated proxy class is also given final and public access attributes, and its naming convention is similar to "parent class name +proxyn" (N is also an incremented Arabic number). Finally, the exception handling is consistent with the original.
Figure 2. Inherited graphs of dynamically generated proxy classes