另有一個詳細版在這里
Jdk1.5中加入了泛型,解決了很多實際的問題,具體內容講解見候捷的文章:http://jjhou.csdn.net/javatwo-2004-gp-in-jdk15.pdf
下邊是一個使用的簡單實例
import java.util.ArrayList;
import java.util.HashMap;
public class TestGeneric {
?public static void main(String[] args){
??//need not cast
??ArrayList<String> strList = new ArrayList<String>();
??strList.add("1");
??strList.add("2");
??strList.add("3");
??String str = strList.get(1);
??System.out.println("str="+str);
??
??//autobox
??ArrayList<Integer> iList = new ArrayList<Integer>();
??iList.add(1);
??iList.add(2);
??iList.add(3);
??int num = iList.get(1);
??System.out.println("num="+num);
??
??//double generic
??HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
??map.put(1, 11);
??map.put(2, 22);
??map.put(3, 33);
??int inum = map.get(1);
??System.out.println("inum="+inum);
?}
}