Newinstance example:
/* String classname = "Class Name ";
Class classxml = Class. forname (classname );
Domxml dx = (domxml) classxml. newinstance ();
*/String classname = "domxml ";
Class classxml = Class. forname ("domxml ");
Domxml dx = (domxml) classxml. newinstance ();
New example:
Domxml dx = new domxml ();
When using the keyword new to create an instance, this class can not be loaded, but the newinstance method must ensure that a and class are loaded; B and class are connected. The above two steps are completed by the static class method forname. In fact, newinstance breaks down the new step into two steps, that is, it first calls the class loading method to load a class and then instantiates it.
Differences between them:
Newinstance is weak and inefficient. It can only be called without parameter construction;
New: strong type, relatively efficient, can call any public structure.