Steps of JDK dynamic proxy generation object

principle

JDK dynamic proxy uses byte reorganization to regenerate objects to replace original objects to achieve the purpose of dynamic proxy.

Steps of JDK dynamic proxy generation object

  1. Get the reference of the proxied object, and get all its interfaces, and get it by reflection.
  2. The JDK dynamic proxy class regenerates a new class, and the new class must implement all the interfaces implemented by the proxy class.
  3. Java code is dynamically generated, and the newly added business logic method is called by a certain logic code (reflected in the code).
  4. Compile the newly generated Java code .class file.
  5. Reload it into the JVM to run.

The above process is called bytecode reorganization

There is a specification in the JDK. As long as the .class file starts with $ under ClassPath, it is generally automatically generated

Source address: https://github.com/lee58/designPattern.git

Guess you like

Origin blog.csdn.net/qq_37335220/article/details/113461659