Explanation
1. JDK dynamic proxy does not need to implement the interface, only the target object needs to implement the interface.
2. The interface-based dynamic proxy needs to use the API in the JDK to dynamically construct the Proxy object in the JVM memory.
3. You need to use the java.lang.reflect.Proxy and newProxyInstance methods, but this method needs to receive three parameters.
Example
public class BusinessAgent implements Sell { private Vendor mVendor; public BusinessAgent(Vendor vendor) { this.mVendor = vendor; } public void sell() { System.out.println("before"); mVendor.sell(); System.out.println("after"); } public void ad() { System.out.println("before"); mVendor.ad(); System.out.println("after"); } }
The above is the detailed content of What are the characteristics of java dynamic proxy?. For more information, please follow other related articles on the PHP Chinese website!