Java reflection defines, obtains Class three methods, class Three Methods
Reflection mechanism definition:
When running (dynamic), all attributes and methods of this class can be obtained for any class.
Any attributes and methods of an object can be called.
The Class is the origin of the reflection mechanism. We can obtain three methods for Class objects:
First: Obtained by Class Name
Class <?> Class = ClassName. class;
Method 2: Get through the full path of the Class Name:
Class <?> Class = Class. forName ("class Name full path ");
Third: Get Through instance object:
Class <?> Class = object. getClass ();
Sum up the differences between the three methods through code: (add tomorrow)
1 class Test {2 static {3 System. out. println ("static code block"); 4} 5 {6 System. out. println ("dynamic code block"); 7} 8}
1 public class ClassCreate {2 public static void main (String [] args) {3 Class <?> Test2 = Test. class; 4 System. out. println ("test"); 5} 6}