離弦之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ù)天空 閱讀(939) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 晋宁县| 江城| 肇东市| 松江区| 潮安县| 晋城| 扎囊县| 额济纳旗| 叙永县| 无锡市| 临桂县| 禄丰县| 化德县| 乐安县| 兴业县| 玉山县| 仪征市| 霍州市| 台前县| 石泉县| 衡阳县| 北票市| 阿荣旗| 天峻县| 谢通门县| 隆回县| 桦川县| 高清| 安顺市| 和龙市| 水富县| 成安县| 江津市| 日喀则市| 沂南县| 施秉县| 汉阴县| 新余市| 黄石市| 措勤县| 台北县|