Explain the reflection mechanism in Java (including array parameters)

Explain the reflection mechanism in Java (including array parameters)

Java reflection is what I always like very much, because with this, the flexibility of the program can be greatly increased, and the universality can be improved a lot. I don't want to make a big introduction to the principle of reflection. A search on the Internet will give me a lot. (I'll just introduce the appendix below)

Reflection is a key property of Java as a dynamic (or quasi dynamic) language. This mechanism allows programs to obtain the internal information of any class with a known name through reflection APIs at runtime, including its modifiers (such as public, static, etc.), superclass (such as object), and implemented interfaces (e.g. clonable), which also includes all information about fields and methods, and can change the contents of fields or evoke methods at run time

here What I want to say is that if we do what we want according to the string (including dynamically executing the corresponding methods and generating the corresponding classes), most of us pass the string when transmitting data (HTTP, socket), etc. when we receive these strings, we can do the corresponding things according to the contents of these strings. That's a very good thing. We can call methods remotely (the client sends the specified string and the server executes the corresponding methods according to the reflection). In fact, I have also done such projects, the client (not written in Java language) use socket to call server (written in Java) methods, and directly pass parameters. These are implemented according to java reflection technology. Well, let's talk more about others. From the most basic point of view, here is a most basic reflection method

When compiling and executing, you can see the desired results. Imagine turning those strings into data passed from other places:)

Another method has array reflection. I studied it. There is a little difference. Everyone should look carefully

Well, basically, no matter how complex the program is, it has evolved from the foundation. I learned a lot here:)

If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

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
分享
二维码
< <上一篇
下一篇>>