Java Trivia Point 6

Source: Internet
Author: User

Code written with a generic mechanism has better security and readability in code that enforces type conversions than those that are cluttered with variables that use the type object.

Generic class:

The type variable t is placed after the class name, with <>, and the generic class can be regarded as the factory of the ordinary class.

Generic methods:

The generic is placed after the modifier and returns the front of the type.

Qualification of generic type variables:

Whether a generic type is defined appropriately, a corresponding primitive type erase type variable is automatically supplied, replaced with a qualified type (No limit to object)

The compiler automatically inserts force type catch.

Constraints:

    • You cannot instantiate a generic parameter with a base type
    • Run-time type queries apply only to the original type (a instanceof pair<string>, false)
    • Cannot create an array of parameterized types
    • Cannot instantiate type variable (new T ())
    • Cannot reference a type variable in a static field or method
    • An instance of a generic class cannot be thrown or captured

Two classes have an inheritance relationship, the generic class is not connected

Wild-Letter wildcard types:

Wildcard characters can also specify a super-type qualification:? Super Manager

Wildcard characters with a super-type qualification can be written to generic objects, and wildcard characters with sub-type qualification can be read from generic types.

Java Trivia Point 6

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.