定义
(①)基本概念:
1.泛型变量(type variable)
JSL中有如下三句话
2)A type variable is an unqualified identifier used as a type in class, interface, method, and constructor bodies.
3)A type variable is introduced by the declaration of a type parameter of a generic class, interface, method, or constructor.
可以看出,type variable被当做一种引用类型在java中使用。通过定义泛型类、接口、方法、构造函数,引入泛型变量。则在该泛型变量的作用范围为, 该标识符可以被当做某种 “引用类型” 使用
既然是变量,则有scope概念泛型类:
1)the type parameter section of the class declaration
2)the type parameter section of any superclass or superinterface of the class declaration
3)the class body.
泛型接口:
1)the type parameter section of the interface declaration
2)the type parameter section of any superinterface of the interface declaration
3)the interface body.
2.泛型(generics)【广义的泛型,可以理解为泛型技术】泛型方法:the entire declaration of the method, including the type parameter section, but excluding the method modifiers.泛型构造器:the entire declaration of the constructor, including the type parameter section, but excluding the constructor modifiers.
3.泛型(generic type)【狭义的泛型,可以理解为使用泛型技术的type】Generics allow you to abstract over types,模板类型概念?
4.参数化类型(parameterized type)JDK5之前,type:class type、interface type、array type故generic type可以理解为:对JDK5之前的类型,应用泛型技术generics,得新类型:泛型类、泛型接口、泛型数组(因为类型擦除等Java中无真正的泛型数组)细究无益:可以片面的理解为在声明类、接口时,引入类型变量用作 类型形参。如:JDK中List<E>的定义
5.原生类型(raw type)A parameterized type is a class or interface type of the form C<
T1,..., Tn>
, where C is the name of a generic type and<
T1,..., Tn>
is a list of type arguments that denote a particular parameterization of the generic type.可以理解为,generic type的实际使用,传入类型实参后所得的类型。如,List<Integer> list;
对于在声明时引入类型变量的类或接口,在实际使用时不传入类型实参,将其当做JDK5之前的类型使用。如,List list;
(②)泛型类、泛型接口、泛型方法、泛型构造函数
interface MyList<E,T extend E> extend List<E>{}
可以看出这里对于泛型接口 MyList,有type variable E,分别用在了type parameter section(T extend E)、type parameter section of superinterface(List <E>)泛型类、泛型接口、泛型方法、泛型构造函数的声明见~