Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of dynamically generating proxy Class by java

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this "java dynamic generation proxy class method" article, so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "java dynamic generation proxy class method" article.

Description

1. Call the newProxyInstance method of the Proxy class to get the proxy class instance.

2. This proxy class implements the specified interface and distributes the method calls to the specified call handler.

Method declaration

Public static Object newProxyInstance (ClassLoader loader, Class [] interfaces, InvocationHandler h) throws IllegalArgumentException

Parameters.

Loader: defines the ClassLoder of the proxy class

Interfaces: list of interfaces implemented by the proxy class

H: call the handler, which is the instance of the class we defined above that implements the InvocationHandler interface

Example

Public class Main {public static void main (String [] args) {/ / create a mediation class instance DynamicProxy inter = new DynamicProxy (new Vendor ()); / / add this sentence to generate a $Proxy0.class file, which is the dynamically generated proxy class file System.getProperties (). Put ("sun.misc.ProxyGenerator.saveGeneratedFiles", "true") / / get the proxy class instance sell Sell sell = (Sell) (Proxy.newProxyInstance (Sell.class.getClassLoader (), new Class [] {Sell.class}, inter)); / / call the proxy class method through the proxy class object, which will actually go to the invoke method call sell.sell (); sell.ad () }} the above is the content of this article on "the method of dynamically generating proxy classes in java". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report