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
- Get the reference of the proxied object, and get all its interfaces, and get it by reflection.
- The JDK dynamic proxy class regenerates a new class, and the new class must implement all the interfaces implemented by the proxy class.
- Java code is dynamically generated, and the newly added business logic method is called by a certain logic code (reflected in the code).
- Compile the newly generated Java code .class file.
- 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