Method a : manually create and instantiate,
1, to create an object,
The Class Class=null;
2, use the new keyword to instantiate the class,
Class=new class ();
Usually written: Class Class=new Class ();
Method of 2 : the use of other classes to return an instance of the object,
1, to create an object, used to receive the returns an instance of the object,
The Iterator Iterator=null;
2, can call a method returns the instance objects, such as: the list. The Iterator ();
The iterator=list. The iterator ();
Usually written: Iterator Iterator=list. The Iterator ();
[this is the 20th day I learn Java, when using iterators, instantiation of the process is different with usual, confused for a moment, I am the kind of person who don't understand just don't remember, share with you, so write hope to help beginners!]
CodePudding user response:
You return values of the iterator is method not create objectsTwo methods to create objects is
1 call new method to construct
2 using the reflection, call Class object. NewInstance () or a Class object. GetDeclaredConstructor (). The newInstance ()
CodePudding user response: