201671010106 2016--2017 "Java Programming" learning experience 8

Source: Internet
Author: User
Tags class definition

generics, also known as parameterized types, are used when defining classes, interfaces, and methods by indicating the type of object to be processed by the type parameter, which can be reused by many different types of objects

generic programming is implemented using inheritance before adding generic classes in Java. For type parameters, this code might be useful for all of the built-in classes, and the type variables in the class definition are used to specify the return type of the method and the type of the domain, local variable.

declaration of a generic method: in addition to generic classes, you can define only one method as a generic method, specifying either a method parameter or a return value of a generic type, to be determined when the method is called. A generic method can be declared in a generic class or declared in a normal class.

constraints and limitations of generic classes: type parameters cannot be instantiated with a base type, run-time type queries only apply to primitive types, cannot be thrown or catch generic class instances, arrays of parameterized types are illegal, type variables cannot be instantiated, type variables are invalid in static contexts of generic classes, note conflicts after Erasure

By understanding the three examples in the book, I learned how to define a generic class, introduce generic variables, define simple methods with type parameters, or more to understand code examples on a book, and learn by commenting on the code.

201671010106 2016--2017 "Java Programming" learning experience 8

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.