201671010116.2016-2017-10 "Java Programming" 10th Week study Summary

Source: Internet
Author: User

This week, we learned about generic programming and learned about the benefits of generic methods, which are that generic classes improve the type safety of Java programs, eliminate forced type conversions, and increase the reuse rate of code.

A generic parameter type can use the extends statement to define the upper bounds of a generic variable, and the upper bound declared by the extends keyword can be either a class or an interface. Classes handled by T in the public numbergeneric<t extends number> must have an inheritance relationship with number. The reason for choosing extends is closer to the concept of subclasses. Of course, a generic parameter type can also use the Super statement to define the lower bound of a generic variable, such as list< Super Cashcard>cards=new arrayslist<t> (), the Super keyword can pin the type of a generic parameter to a type or its superclass. Wildcard characters, such as public static<t> void sort (t[] a,compartor< super t> C), are commonly used when qualifying types for a method's parameters

Arrays are covariant, but covariance cannot be used in generic types, which destroys the type-safe generics that will be provided. There is also a confusing distinction in this chapter: T denotes an unknown type, and a wildcard? Represents any one type

During the experiment, it was found that the generic method would not be used. You can understand the meaning when reading a textbook, but it will not be used in a specific program.

201671010116.2016-2017-10 "Java Programming" 10th Week study Summary

Related Article

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.