I. Background overview of reflection mechanism
1. Reflection (reflection) is a key property of Java as a dynamic language
2, reflection mechanism refers to the program at runtime to obtain any class of all internal information
Second, the reflection mechanism realizes the function summary
1, as long as the full name of the given class, you can get all the information of the class through reflection
2, the program is running is able to get any object belonging to the class object
3. At run time, you can get all the properties of a class and manipulate it
4, at run time can get the class, all the methods of the parent class and call
5, the current mainstream framework struts2, srping, hiberate and other framework of the core functions are through the Java reflection mechanism to achieve
Mechanism and realization of reflection-related objects
1. The Mechanism and implementation of class object
(1) Class Object Overview
Class is the type of classes
(2) Class common methods
GetName () Gets the full name of the class
Getdeclaredfields () gets all the properties in the class
Getdeclaredmethods () gets all the methods in the class
GetConstructors () Get the method of constructing class
Newinstance () instantiating an object of a class
Wait a minute..
2. Three ways to get classes
(1) Class.forName (String className),ClassName must be the full path of the class
(2) Book book = new book (); Book.getclass ();
(3) Book.class;
In the Java reflection mechanism, there are many important objects, such as Field,method, which are not described here, and can be viewed Javaapi to understand its functionality.
An overview of the reflection mechanism in Java reflection learning