reprinted from concurrent Programming network –ifeve.com
The Java reflection mechanism allows us to check the information of classes, interfaces, variables, and methods at run time (runtime) outside of the compile period (Compile time). Reflection also allows us to instantiate an object at run time, invoke a method, and get the value of a variable by calling the Get/set method.
The Java reflection mechanism is powerful and functional. For example, you can use a reflection mechanism to map a Java object to a database table, as butterfly persistence (a framework written by the original author), or a statement in a script that maps to the corresponding object invocation method at run time, like Butterfly Container (Translator Note: The framework written by the original author) is done when parsing its configuration script.
There are a plethora of Java reflection guides already on the Internet, but most of the guidelines, including the reflection guidelines released by Sun, only introduce some of the reflective surface content and its potential.
In this series of articles, we will understand the Java reflection mechanism more deeply than other guidelines, and it will explain how the basic principles of the Java Reflection mechanism include the use of arrays, annotations, generics, and dynamic loading of classes and the implementation of overloads of classes. It also shows you how to implement some features that are more characteristic, such as reading all the Get/set methods from a class, or accessing private variables of a class and private methods. This series of guides also explains some of the non-reflection-related but confusing issues, such as which generic information is valid at run time, and some people claim that all generic information disappears during runtime, but this is not true.
The article in this series describes the reflection mechanism in Java version 6.
- Java Reflection Tutorials
- Java Reflection (i): Java Reflection Guide
- Java Reflection (ii): Classes
- Java Reflection (iii): constructors
- Java Reflection (iv): variables
- Java Reflection (V): Methods
- Java Reflection (vi): Getters and Setters
- Java Reflection (vii): Private variables and private methods
- Java Reflection (eight): annotations
- Java Reflection (ix): generics
- Java Reflection (10): Arrays
- Java Reflection (11): Dynamic Proxy
- Java Reflection (12): Dynamic class loading and overloading
Original address Author: Jakob Jenkov Translator: Yevenhai ([email protected]) proofreading: Fang Fei
Java Reflection Tutorials