Talk about java reflection

The java reflection mentioned this time involves a lot of code. Because reflection is often used in work, a lot of abstractions and filters are made to the code. Although there is a lot of code, it is easy to use and the filter plug-in is easy to modify.

The following describes where reflection is easy to use in work. For example, if there are few Abstract subclasses for plug-ins or filters, the same effect can be achieved by configuring them into XML and other structures. If you want to be flexible, you can use it directly after adding plug-ins or filter code subclasses. Maybe the reflection will be better. Scan all class or jar files to get all inherited subclasses. If all files are scanned for each call, performance will be affected. Therefore, add reflection cache in the implementation, and cache all reflection results as a key for all parameters involved in obtaining reflection subclasses. Next time, if it is the same key, it will not be rescanned.

Code examples are as follows:

Code execution result:

How to implement specific classes? Let's look at the source code. Here are the codes of two core classes. Source address: https://git.oschina.net/eliyanfei/api_tools

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>