Definition of reflection mechanism:
In a running state (dynamic), all properties and methods of this class are available for any class.
For any object, you can call any of its properties and methods.
Class is the origin of the reflection mechanism, we have 3 ways to get class objects:
The first type: obtained by the class name
Class<?> class = Classname.class;
The second type: The full path of the class name is obtained:
Class<?> class = Class.forName ("Class name full path");
The third type: Through the instance object gets:
Class<?> class = Object.getclass ();
Summarize the differences between the three methods by code: (Make Up Tomorrow)
1 class test{ 2 Static { 3 System.out.println (" Static code block " 4 } 5 { 6 System.out.println ("Dynamic code block D Ynamic code block " 7 } 8 }
1 Public class classcreate { 2public staticvoid main (string[] args) { 3 Class<?> test2=test.class; 4 SYSTEM.OUT.PRINTLN ("test"); 5 } 6 }
Java reflection definition, get class three methods