Key Java Technologies (21) Characteristics of parametric types of generics (cont.)

Source: Internet
Author: User

1.1. characteristics of parameterized types 2

There are two parameterized types with different type parameters but there is an inheritance relationship, and still cannot be mixed. The inheritance relationship of a type parameter cannot deduce that the parameterized type has an inheritance relationship.

 Public classGenericParameterTest2 {Static classBase {}Static classDerivedextendsBase {}Static classGeneric<t>{}  /** * @paramargs*/ Public Static voidMain (string[] args) {//correct usage, t all are baseGeneric<Base> Base =NewGeneric<base>(); //correct usage, T is all derivedGeneric<Derived> Derived =NewGeneric<derived>(); //error usage. The t of the two is not the same. //generic<base> base2 = new generic<derived> ();//error usage. The t of the two is not the same. //generic<derived> derived2 = new generic<base> (); //correct usage. Primitive type, you can use parameterized types of any type parameter to assign values. Generic Base4=NewGeneric<base>(); //correct usage. Primitive types can assign values to parameterized types of any type parameter. Generic<Base> BASE5 =NewGeneric ();} 

Key Java Technologies (21) Characteristics of parametric types of generics (cont.)

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.