DANCE WITH JAVA

          開發出高質量的系統

          常用鏈接

          統計

          積分與排名

          好友之家

          最新評論

          jdk1.5中的新特性 --- 泛型(簡版)

          另有一個詳細版在這里
          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);
          ?}
          }

          posted on 2006-11-06 18:29 dreamstone 閱讀(373) 評論(0)  編輯  收藏 所屬分類: jdk相關

          主站蜘蛛池模板: 达孜县| 岫岩| 抚远县| 襄樊市| 盐城市| 晋城| 龙井市| 周至县| 前郭尔| 历史| 东阳市| 浦城县| 浦东新区| 连城县| 南丰县| 白山市| 葫芦岛市| 房产| 宜君县| 恩施市| 西乌珠穆沁旗| 湖北省| 潍坊市| 内丘县| 璧山县| 九江市| 南郑县| 漯河市| 伊吾县| 盐边县| 卢龙县| 福州市| 昆明市| 深州市| 鱼台县| 崇阳县| 邵东县| 错那县| 黎城县| 昆山市| 阿拉善盟|