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.)