restricting wildcard characters
Keynote Teacher: Wang Shaohua QQ Group: 483773664 Learning Goals
1. Limit the upper boundary of a wildcard
2. Limit the bottom bounds of the wildcard
3. Qualifying wildcard is some type of interface
First, set the upper limit of the type wildcard character
(a) demand
If we don't want this list<?> to be any generic list, just want to indicate that it is the parent class of a generic list of a certain type.
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/80/3D/wKiom1c78mTQ1JjhAAAAK9URceg081.gif " data_ue_src= "E:\My knowledge\temp\0384a27e-3831-4e07-911a-d52de8586733.png" word_img= "file:///E:/My%20Knowledge/ Temp/2a836208-3c11-4e71-ba09-ee2fcbfcd6bf_36_files/0384a27e-3831-4e07-911a-d52de8586733.png ">
For example, an element in a list can only be an employee class and its subclasses.
(ii) grammar
(iii) achieving
12 |
public class Employee extends Person{ } |
12 |
public class Manager extends Employee{ } |
12345 |
public class needs1 { public void test (list<? extends employee> list { } } |
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/80/3D/wKiom1c78mTQ1JjhAAAAK9URceg081.gif " data_ue_src= "E:\My knowledge\temp\01236977-ecef-4ddc-8212-edd657e36599.png" word_img= "file:///E:/My%20Knowledge/ Temp/2a836208-3c11-4e71-ba09-ee2fcbfcd6bf_36_files/01236977-ecef-4ddc-8212-edd657e36599.png ">650) this.width =650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/80/3B/wKioL1c7806T2Dx3AAA2PUMRvxU743.png "data_ue_src=" e:\ My Knowledge\temp\779b14cd-609a-43c5-9c13-bb1c058138ed.png ">
Second, type wildcard character lower bound (a) syntax
Scope of the parameter type: itself and its parent class
(b) Test code
12345 |
public class needs1 { public void test (list<? Super employee> list) { } } |
650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/80/3D/wKiom1c78mTQ1JjhAAAAK9URceg081.gif " data_ue_src= "E:\My knowledge\temp\f667aa48-d33b-4c17-8b07-eb433addaeae.png" word_img= "file:///E:/My%20Knowledge/ Temp/2a836208-3c11-4e71-ba09-ee2fcbfcd6bf_36_files/f667aa48-d33b-4c17-8b07-eb433addaeae.png ">650) this.width =650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M01/80/3D/wKiom1c78mTyqJ0CAAA3OBTFCRw249.png "data_ue_src=" e:\ My Knowledge\temp\e9b0f833-51b9-4cf4-bc47-ed94326f53c6.png ">
Three, interface (i) syntax
Only allow generics to invoke references to implementation classes that implement the comparable interface
Iv. Learning Video URL:
Http://edu.51cto.com/course/course_id-6083.html
From for notes (Wiz)
Learn from teacher Wang Generics (vii): Restrict wildcard characters