隨筆 - 154  文章 - 60  trackbacks - 0
          <2008年4月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          聲明:

          該blog是為了收集資料,認(rèn)識(shí)朋友,學(xué)習(xí)、提高技術(shù),所以本blog的內(nèi)容除非聲明,否則一律為轉(zhuǎn)載!!

          感謝那些公開自己技術(shù)成果的高人們!!!

          支持開源,尊重他人的勞動(dòng)!!

          常用鏈接

          留言簿(3)

          隨筆分類(148)

          隨筆檔案(143)

          收藏夾(2)

          其他

          學(xué)習(xí)(技術(shù))

          觀察思考(非技術(shù))

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          從JDK5.0開始出現(xiàn)的泛型(Generics)功能。泛型提供編譯時(shí)期的檢查,不會(huì)將對(duì)象置于某個(gè)容器而失去其類型。

          http://www.onjava.com/pub/a/onjava/excerpt/javaian5_chap04/index.html

          這個(gè)是JDK   1.5   的新特性。
          舉個(gè)例子。  
          一個(gè)列表中加入3個(gè)數(shù)字,然后從列表中取出作合計(jì)的操作。

          JDK   1.4   的時(shí)候
          List   testList   =   new   ArrayList();
          testList.add(new   Integer(100));
          testList.add(new   Integer(200));
          testList.add(new   Integer(300));
          int   result   =   0;
          for(int   i   =   0;   i   <   testList.size();   i   ++)   {
                  //   這里從列表中取數(shù)據(jù)時(shí),需要強(qiáng)制轉(zhuǎn)換。
                  result   +=   (Integer)testList.get(i).intValue();
          }
          System.out.println(result);


          JDK   1.5   的時(shí)候
          List <Integer>   testList   =   new   ArrayList <Integer> ();
          //   注意,JDK1.5的   int   的   100,能夠自動(dòng)的轉(zhuǎn)換成   Integer   類型。不強(qiáng)制要求   new   Integer(100)
          testList.add(100);
          testList.add(200);
          testList.add(300);
          int   result   =   0;
          for(int   i   =   0;   i   <   testList.size();   i   ++)   {
                  //   這里從列表中取數(shù)據(jù)時(shí),不需要強(qiáng)制轉(zhuǎn)換。
                  result   +=   testList.get(i).intValue();
          }
          System.out.println(result);

          posted on 2008-04-08 16:07 lk 閱讀(2093) 評(píng)論(0)  編輯  收藏 所屬分類: j2se
          主站蜘蛛池模板: 百色市| 东阿县| 治县。| 晴隆县| 宜城市| 顺义区| 调兵山市| 苗栗市| 福建省| 清流县| 舞钢市| 静乐县| 房山区| 余庆县| 松溪县| 永定县| 柞水县| 黎川县| 安岳县| 大港区| 平果县| 阿克苏市| 浠水县| 琼结县| 木里| 方正县| 福建省| 宜章县| 株洲市| 天等县| 炉霍县| 工布江达县| 清水县| 榆社县| 金门县| 阿尔山市| 准格尔旗| 舒兰市| 县级市| 梅州市| 诸城市|