Java notes about generics

Source: Internet
Author: User

The main reason for increasing the generic mechanism in 1.Java SE 5.0 was to meet one of the earliest Java specification requirements developed in 1999 (JSR 14).

2. Program code written using the generic mechanism has better security and readability than the clutter of code that uses the object variable and then enforces the type conversion.

3. The charm of type parameters is: Make the program more readable and secure

4. Generic methods can be defined in a normal class or in a generic class

5. Generics can not only limit downward, such as < Extends Collection>, can also limit upward, such as <? Super Double>, which indicates that a type can accept only Double and its upper-parent class type, such as number, an instance of type object.

6. A type variable or wildcard can have multiple qualifications, for example: T extends comparable & Serializable

7. Virtual machine Heavy No generics, only common classes and methods

8. All type parameters have their qualified type substitution

9. Bridge method is synthesized to protect polymorphic

type erase : Whenever a generic type is defined, it automatically provides a corresponding primitive type (raw type). The name of the original type is the generic type name after the type parameter is deleted. Erase (erased) type variable and replace with qualified type (unqualified variable with object)

Java notes about 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.