java5 泛式中的 T是什么意思?
public class classA<T>{}

public class classA{}
有什么区别?

解决方案 »

  1.   

    楼主可以看看这篇文章,写的挺详细的:
    http://liutiegang2.itpub.net/post/24466/228748
      

  2.   

    这个是java5.0的新特性:定义泛型类.
    作用有点像(2楼所说)C++的模板template.
    个人觉得"泛型"在集合类Collection里有作用,对定义泛型类(就像lz所提),泛型方法没有多大的意义
      

  3.   

    接上:
    public class classA <T>{} 
    和 
    public class classA{} 
    有什么区别?是:
    1>public class classA{} 里的对象类变量,或返回对象类型的方法,这些属性可以"随意定".如
      public class classA{
                           Object o1;    --Object类型类变量
                           Animal a1;    --Animal类型类变量
                              Cat    c1;    --Cat类型类变量
                              Integer fun(){} --返回Integer对象类型的方法

    1>public class classA <T>{} 里如果有如上的类变量和方法,则这些的属性必须是T类型.
     public class classA<Integer>{
                           Integer o1;    --Integer类型类变量
                              Integer a1;    --Integer类型类变量
                              Integer c1;    --Integer类型类变量
                              Integer fun(){} --返回Integer对象类型的方法
      

  4.   

    就是泛型参数哦,不用 T 用其他字母也行。用 T 只是习惯性,表示 Type。也可以看到在泛型集合类中也有用到 E、K、V 什么的,分别表示 Element, Key, Value 用的
    字母只是一个代号,并不是一定得用这个字母的  :)
      

  5.   


    我认同表示template
    呵呵
    不过就像果子说的
    什么字符都是可以的
      

  6.   

    不会啊 T 就是表示 Type 的啊参见 Java Tutorial 中关于泛型的部分(http://java.sun.com/docs/books/tutorial/java/generics/gentypes.html):The most commonly used type parameter names are:    * E  -  Element (used extensively by the Java Collections Framework)
        * K  -  Key
        * N  -  Number
        * T  -  Type
        * V  -  Value
        * S,U,V etc.  -  2nd, 3rd, 4th types You'll see these names used throughout the Java SE API and the rest of this tutorial.