Extends and Super keywords in Java generics

Source: Internet
Author: User

Understand List<? Extends t> list, T key, comparator<? Super T> C

These are generally used on method parameter types to accept generic objects.

1, list<? Extends t> represents a subclass of any T, such as list< Extends person> indicates that any generic type can be accepted as a list object of any person subclass, which is generally used for method invocations, which represents each of the accepted list<? The elements in extends person> are all a person and contain the function interface of person.


2, comparator<? Super T> represents the parent class or ancestor of any T, comparator< Super Student> can indicate that accepting any one of the generic types is a comparator of the Student parent class, such as a comparator<person> can sort all the person, Then nature can also give student sort.

Extends and Super keywords in Java generics

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.