The Java reflection mechanism is used to dynamically generate classes at runtime information or methods, properties, can also be used for dynamic generation of classes, because all classes are subclasses of class, we can use a class class instance to instantiate a variety of classes
For example:
NULL ; Classnull; // notation 1, may throw classnotfoundexception [multi-use this notation ] Class1 = Class.forName ("Cn.lee.demo.Person"); System.out.println ("Demo2: (notation 1) package name:" + class1.getpackage (). GetName () + "," + "full class Name:" + Class1.getname ( )); // notation 2 Class2 = person. class ; System.out.println ("Demo2: (notation 2) package name:" + class2.getpackage (). GetName () + "," + "full class Name:" + class2.getname ());
It's a common form.
There is another way to get internal methods/properties
NULL ; = Class.forName ("Cn.lee.demo.Person"); = class1.newinstance (); = Class1.getdeclaredfield ("name"); Personnamefield.setaccessible (true); " Fat Tiger First Sen "); System.out.println ("Demo5: Gets the value of the property variable after modifying the property:" + personnamefield.get (obj));
You can manipulate properties and methods inside a class
Java Reflection Mechanism Learning essays