Learn from teacher Wang Generics (vii): Restrict wildcard characters

Source: Internet
Author: User

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
1 <? extendssuperClass>
(iii) achieving
12 publicclassPerson {}
12 publicclass Employee extendsPerson{}
12 publicclass Manager extendsEmployee{}
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
1 <? supersubClass>

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
1 <? extendsComparable>

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.