Android (Java) Learning Note 91: Overview and use of generic interfaces

Source: Internet
Author: User

1  Package cn.itcast_06; 2 3 /* 4 * Generic interface: Define generics on the interface 5  */ 6  Public Interface Inter<t> {7public     abstractvoid  show (T t); 8 }

1  Packagecn.itcast_06;2 3 //Implementing a class when implementing an interface4 //The first case: you already know what the type is.5 6 //Public class Interimpl implements inter<string> {7 //8 //@Override9 //Public void Show (String t) {Ten //System.out.println (t); One //    } A // } -  - //The second case: I don't know what type it is. the  Public classInterimpl<t>ImplementsInter<t> { -  - @Override -      Public voidShow (T t) { + System.out.println (t); -     } +}

1  Packagecn.itcast_06;2 3  Public classInterdemo {4      Public Static voidMain (string[] args) {5         //test of the first case6         //inter<string> i = new Interimpl ();7         //i.show ("Hello");8 9         // //test of the second caseTeninter<string> i =NewInterimpl<string>(); OneI.show ("Hello"); A  -Inter<integer> II =NewInterimpl<integer>(); -Ii.show (100); the     } -}

Android (Java) Learning Note 91: Overview and use of generic interfaces

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.