Java Generic Learning Notes-(v) Generic interfaces

Source: Internet
Author: User

The so-called generic interface, similar to a generic class, is to define generics on the interface, in the following format:
  Public interface Interface name < type parameters >
Such as:

1 Interface Inter<t> {2public     void  show (T t); 3 }

There are two ways to implement it:
1. Specify generics at implementation time:

1 class Implements Inter<string> {23    @Override4      public  void  Show (String t) {5        System.out.println (t); 6     }7     8 }

2. When instantiating, specify the generic type:

1 class Implements Inter<t> {23    @Override4public     void  Show (T t) {5        System.out.println (t); 6     }7     8 }

Call:

1 New A (); 2 a.show ("hi!" ); 3 New B<>(); 4 b.show (true);

Java Generic Learning Notes-(v) 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.