Summarize the relevant knowledge points of the Java reflection mechanism,
I. What is reflection
The Java reflection mechanism is in the running state, for any class can know its properties and methods, for any object can call its properties and methods, this dynamic access to information or the function of dynamic Call object method is called Java Reflection mechanism;
Two. Three ways to get class
1 Public classFanshe {2 //three ways to get a class object 3 Public Static voidMain (string[] args) {//product is the base class of its own definition, placed in the Fanshe package 4Product p =NewProduct ();5 //1. Through the GetClass () of the object; 6Class C1 =P.getclass ();7System. out. println (C1.getname ());8 //2. Static class properties by data type 9Class C2 = Product.class;TenSystem. out. println (c1==C2); One //3. Static Methods A Try { -Class C3 = Class.forName ("Fanshe. Product");//string full path contains package name -System. out. println (c3==C2); the}Catch(ClassNotFoundException e) { - //TODO auto-generated Catch block -e.printstacktrace (); - } + } -}
Java Reflection mechanism