A simple use of reflection in Java
brief introduction
Firstly, some impractical explanations are introduced: the java reflection mechanism is that all the properties and methods of any class can be known in the running state; For any object, you can call any of its methods and properties; This function of dynamically obtaining information and dynamically calling object methods is called the reflection mechanism of Java language.
Simple use
Reflection is a very common and easy-to-use way in Java, (but you need to know that its efficiency is relatively low, so it should be used with caution) of course, it can also be used in Android based on Java language. We can use reflection to obtain some classes that are not open in the system, so as to call some of its methods. Here is a simple description of how to use java reflection to obtain classes and call its methods Now.
Let's take a look at what is done in stringtoup:
In fact, it is a string converted to uppercase and returned. Well, let's take a look at the output result:
It's perfect.
summary
Well, the above is the whole content of this article. Reflection has a wide range of applications in Android. For example, when our project has multiple modules, you can call a method of the main program in the module. You can also use reflection to call some public methods of the system, but the efficiency is not very high. I hope the content of this article is helpful for you to learn or use radioactive energy in Java. If you have any questions, you can leave a message.