Dynamic proxy for java

Source: Internet
Author: User

Proxy

Proxy. getProxyClass (ClassLoader loader, Class <?> ... Interfaces) obtains the bytecode object of the proxy Class and returns the Class type.

Proxy. newProxyInstance (ClassLoader loader, Class <?> [] Interfaces, InvocationHandler h) obtains an Instance Object of the dynamic proxy class.

Dynamic Proxy:

Class proxy {

InvocationHandler handler;

ProxyClass (InvocationHandler handler ){

This. handler = handler;

}

Method_1 (Object [] obj ){

Handler. invoke (proxy, Interfaces. getMethod ("method_1"), obj );

}

.....

Method_n (Object [] obj)

Handler. invoke (proxy, Interfaces. getMethod ("method_n"), obj );

 

}

The InvocationHandler object has only one invoke method. This method is equivalent to a relay method. Its Parameter List is the method called by obj-proxy object and method-proxy object, args-list of parameters for calling a method, which is an array of objects. the methods and system functions of the target class are called and implemented in the InvocationHandler's invoke method.

 <! -- [If gte mso 9]> <! [Endif] --> <! -- [If gte mso 9]> <! [Endif] --> <! -- [If gte mso 10]>

Proxy implementation AOP framework


 

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.