離弦之Ray

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            55 Posts :: 0 Stories :: 33 Comments :: 0 Trackbacks
          一直疑惑 ArrayList<int> 怎么搞,但懶得去查,今天網(wǎng)上搜到了:

          The generics facility in Java can be used only for
          object (reference) types.  It cannot be used primitive
          types like 'int' or 'float'.

          So, if you wanted an ArrayList that contained only
          integer data, then you'd need to use the object type
          which corresponds to int: java.lang.Integer.

             ArrayList<Integer> numbers;
             numbers = new ArrayList<Integer>(40);

          Fortunately, the new Autobox/unbox features of Java can
          make this work just like an ArrayList of int.

             numbers.add(27);

          The value 27 will be automatically boxed as an Integer
          object, then added to the ArrayList<Integer>.

          For more information, consult
          http://java.sun.com/developer/technicalArticles/J2SE/generics/index.html
          http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

          posted on 2007-12-23 15:22 離弦之ray的技術(shù)天空 閱讀(935) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 东丰县| 汉源县| 论坛| 仪征市| 互助| 蒙城县| 平遥县| 那坡县| 岑巩县| 搜索| 剑阁县| 綦江县| 玉环县| 大丰市| 察隅县| 杨浦区| 策勒县| 寻乌县| 柏乡县| 武鸣县| 麻阳| 商城县| 铜川市| 佛学| 武平县| 浦县| 名山县| 萨嘎县| 乌兰县| 太保市| 滦南县| 凤城市| 克什克腾旗| 潞西市| 迭部县| 彝良县| 贵定县| 湖北省| 东阳市| 英吉沙县| 轮台县|