Analysis and expansion of Java Dynamic Proxy mechanism, part 2nd

Source: Internet
Author: User
Tags exception handling inheritance naming convention

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.