Introduction and example summary of Java programming reflection mechanism
This article illustrates the usage of Java programming reflection mechanism. Share with you for your reference, as follows:
Reflection: dynamically obtain classes (bytecode files, such as person. Class in this article) and run their members. Reflection may be encountered a little less in the development of Android application layer, but for small partners who want to get through the bottom layer, they must master the operation.
Entity class
Person. java
Method for dynamically obtaining bytecode file
In this article, in order to make the blog posts look concise, all exceptions are thrown and import is omitted, the same below.
Get classes dynamically and create objects
Get the class dynamically and assign values to member variables
Get classes dynamically and execute methods
This is the basic usage of reflection. When we can't create an object normally, we can create an object through the bytecode file of the object and execute the methods therein. Have you learned??
Readers interested in more Java related content can view the special topics of this site: introduction and advanced tutorial of java object-oriented programming, tutorial of Java data structure and algorithm, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills