Explanation
1. The proxy operation is implemented through java.lang.reflect.Proxy, and the proxy object can be created through Proxy's newProxyInstance().
2. You can see that three parameters are required: class loader, interface and call processor. The Class classification is already above. Use class.getClassLoader to get the category loader, and use class.getgetInterfaces() to get all interfaces. Isn't what you want to write now a new InvocationHandler object? In fact, the core code of our dynamic proxy is written here.
Example
Interface implementation class:
public class PersonImpl implements PersonInterface { @Override public void doSomething() { System.out.println("人类在做事"); } @Override public void saySomething() { System.out.println("人类在说话"); } }
Collections in Java are mainly divided into four Class:
1. List: ordered, repeatable;
2. Queue: ordered, repeatable;
3. Set: Non-repeatable;
4. Map mapping: unordered, unique keys, not unique values.
The above is the detailed content of What is the implementation of Java dynamic proxy?. For more information, please follow other related articles on the PHP Chinese website!