Extract Notes
A: The generic type's qualification/** Will the hotel staff, cooks, waiters, managers, respectively stored in 3 sets * Define the method, you can traverse 3 sets at the same time, traverse three sets, you can invoke the working method*/ Importjava.util.ArrayList; ImportJava.util.Iterator; Public classGenerictest { Public Static voidMain (string[] args) {//Create 3 Collection objectsArraylist<chushi> cs =NewArraylist<chushi>(); ArrayList<FuWuYuan> fwy =NewArraylist<fuwuyuan>(); ArrayList<JingLi> JL =NewArraylist<jingli>(); //Each collection stores its own elementsCs.add (NewChushi ("Zhang San", "After kitchen 001")); Cs.add (NewChushi ("John Doe", "After kitchen 002")); Fwy.add (NewFuwuyuan ("Cui Hua", "Service 001")); Fwy.add (NewFuwuyuan ("Sauerkraut", "service 002")); Jl.add (NewJingli ("nickname", "Board of Directors 001", 123456789.32)); Jl.add (NewJingli ("Xiao Qiang", "board 002", 123456789.33)); //arraylist<string> arraystring = new arraylist<string> ();iterator (JL); Iterator (FWY); Iterator (CS); } /** Define the method, you can traverse 3 sets at the same time, traverse three sets at the same time, you can invoke the working method work *? wildcard, iterator It.next () method to take out the object type, how to invoke the Job method cast: It.next ( ) =object o ==> Employee * method Parameters: Control, you can pass the employee object, or you can pass the object of the child class of the employee * Generic qualification of this case, the parent class fixed Employee, but the subclass can be unlimited? * ? Extends employee limit is the parent class, the upper limit, can pass the employee, pass his child class object *? Super Employee restricts the subclass, lower bound, can pass Employee, pass his parent class object*/ Public Static voidIterator (arraylist<?extendsEmployee>Array) {Iterator<?extendsEmployee> it =Array.iterator (); while(It.hasnext ()) {//gets the next () data type, what is the employeeEmployee e =It.next (); E.work (); } } }
Java generic wildcard characters and qualification