pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<i id='0FxaC'><tr id='0FxaC'><dt id='0FxaC'><q id='0FxaC'><span id='0FxaC'><b id='0FxaC'><form id='0FxaC'><ins id='0FxaC'></ins><ul id='0FxaC'></ul><sub id='0FxaC'></sub></form><legend id='0FxaC'></legend><bdo id='0FxaC'><pre id='0FxaC'><center id='0FxaC'></center></pre></bdo></b><th id='0FxaC'></th></span></q></dt></tr></i><div class="fdx322u" id='0FxaC'><tfoot id='0FxaC'></tfoot><dl id='0FxaC'><fieldset id='0FxaC'></fieldset></dl></div>
  1. <small id='0FxaC'></small><noframes id='0FxaC'>

  2. <legend id='0FxaC'><style id='0FxaC'><dir id='0FxaC'><q id='0FxaC'></q></dir></style></legend>
      <bdo id='0FxaC'></bdo><ul id='0FxaC'></ul>

    1. <tfoot id='0FxaC'></tfoot>

      使用 int 與 Integer

      Using int vs Integer(使用 int 與 Integer)

      • <bdo id='RJPFd'></bdo><ul id='RJPFd'></ul>

          <i id='RJPFd'><tr id='RJPFd'><dt id='RJPFd'><q id='RJPFd'><span id='RJPFd'><b id='RJPFd'><form id='RJPFd'><ins id='RJPFd'></ins><ul id='RJPFd'></ul><sub id='RJPFd'></sub></form><legend id='RJPFd'></legend><bdo id='RJPFd'><pre id='RJPFd'><center id='RJPFd'></center></pre></bdo></b><th id='RJPFd'></th></span></q></dt></tr></i><div class="shkxe2k" id='RJPFd'><tfoot id='RJPFd'></tfoot><dl id='RJPFd'><fieldset id='RJPFd'></fieldset></dl></div>
                <tbody id='RJPFd'></tbody>
                <legend id='RJPFd'><style id='RJPFd'><dir id='RJPFd'><q id='RJPFd'></q></dir></style></legend>

                <small id='RJPFd'></small><noframes id='RJPFd'>

                <tfoot id='RJPFd'></tfoot>
                本文介紹了使用 int 與 Integer的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我遇到了一個類,它使用整數變量來捕獲要在 for 循環中使用的大小.這是一種好的做法還是我們應該使用 int 原始數據類型?

                I came across a class using Integer variables to capture size to be used in a for loop. Is this good practice or should we use the int primitive data type?

                Integer size = something.getFields().size();
                for (Integer j = 0; j < size - 1; ++j) 
                

                推薦答案

                提供了 Integer 類,以便可以以純 OO 方式對值進行裝箱/拆箱.在適當的情況下使用 int ,除非您特別需要以 OO 方式使用它;在這種情況下,整數是合適的.

                the Integer class is provided so that values can be boxed/unboxed in a pure OO manner. use int where appropriate unless you specifically need to use it in an OO way; in which case Integer is appropriate.

                Java Int vs Integer

                然而,這里的幕后卻發生了截然不同的事情.int 是一個數字;an > Integer 是可以引用包含數字的對象的指針.

                However, very different things are going on under the covers here. An int is a number; an > Integer is a pointer that can reference an object that contains a number.

                ...

                int 不是對象,不能傳遞給任何需要的方法對象.一個常見的情況是使用提供的集合類(List , Map , Set ) - 盡管可以編寫這些版本提供與對象版本類似的功能的類.這包裝類( Integer , Double 等)經常需要每當使用自省時(例如在反射 API 中).

                An int is not an object and cannot passed to any method that requires objects. A common case is in using the provided collection classes ( List , Map , Set ) - though it is possible to write versions of these classes that provide similar capabilities to the object versions. The wrapper classes ( Integer , Double , etc) are frequently required whenever introspection is used (such as in the reflection API).

                更好地描述何時使用一個與另一個:

                A better description of when to use one vs. the other:

                在 int 和 Integer 之間進行選擇

                Choosing between int and Integer

                在進入之前,我會先介紹如何使用這些類型詳細說明原因.

                I'll start with how these types should be used before going into detail on why.

                • 出于性能原因,首選 int
                • 接受對象的方法(包括像 List<T> 這樣的泛型類型)將隱式要求使用 Integer
                • 使用 Integer 對于低值(-128 到127)因為實習 - 使用 Integer.valueOf(int) 而不是新的整數(int)
                • 不要在整數類型中使用 ==!=
                • 當您需要表示沒有值(null)
                • 注意將 Integer 值拆箱為具有 null 值的 int
                • Prefer int for performance reasons
                • Methods that take objects (including generic types like List<T>) will implicitly require the use of Integer
                • Use of Integer is relatively cheap for low values (-128 to 127) because of interning - use Integer.valueOf(int) and not new Integer(int)
                • Do not use == or != with Integer types
                • Consider using Integer when you need to represent the absence of a value (null)
                • Beware unboxing Integer values to int with null values

                這篇關于使用 int 與 Integer的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                How to convert Integer to int?(如何將整數轉換為整數?)
                How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                Inconsistent behavior on java#39;s ==(java的行為不一致==)
                Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
              • <legend id='anqVm'><style id='anqVm'><dir id='anqVm'><q id='anqVm'></q></dir></style></legend>
                  <tbody id='anqVm'></tbody>
                  <i id='anqVm'><tr id='anqVm'><dt id='anqVm'><q id='anqVm'><span id='anqVm'><b id='anqVm'><form id='anqVm'><ins id='anqVm'></ins><ul id='anqVm'></ul><sub id='anqVm'></sub></form><legend id='anqVm'></legend><bdo id='anqVm'><pre id='anqVm'><center id='anqVm'></center></pre></bdo></b><th id='anqVm'></th></span></q></dt></tr></i><div class="qqxozt8" id='anqVm'><tfoot id='anqVm'></tfoot><dl id='anqVm'><fieldset id='anqVm'></fieldset></dl></div>
                1. <small id='anqVm'></small><noframes id='anqVm'>

                    • <bdo id='anqVm'></bdo><ul id='anqVm'></ul>

                        <tfoot id='anqVm'></tfoot>

                          主站蜘蛛池模板: 合肥宠物店装修_合肥宠物美容院装修_合肥宠物医院设计装修公司-安徽盛世和居装饰 | 泡沫消防车_水罐消防车_湖北江南专用特种汽车有限公司 | 电磁辐射仪-电磁辐射检测仪-pm2.5检测仪-多功能射线检测仪-上海何亦仪器仪表有限公司 | China plate rolling machine manufacturer,cone rolling machine-Saint Fighter | 丁基胶边来料加工,医用活塞边角料加工,异戊二烯橡胶边来料加工-河北盛唐橡胶制品有限公司 | 扬子叉车厂家_升降平台_电动搬运车|堆高车-扬子仓储叉车官网 | 重庆私家花园设计-别墅花园-庭院-景观设计-重庆彩木园林建设有限公司 | 电销卡_北京电销卡_包月电话卡-豪付网络 | 比士亚-专业恒温恒湿酒窖,酒柜,雪茄柜的设计定制 | 头条搜索极速版下载安装免费新版,头条搜索极速版邀请码怎么填写? - 欧远全 | 郑州爱婴幼师学校_专业幼师培训_托育师培训_幼儿教育培训学校 | 浙江宝泉阀门有限公司 | 游动电流仪-流通式浊度分析仪-杰普仪器(上海)有限公司 | 高中学习网-高考生信息学习必备平台| 微量水分测定仪_厂家_卡尔费休微量水分测定仪-淄博库仑 | 河南档案架,档案密集架,手动密集架,河南密集架批发/报价 | 工业胀紧套_万向节联轴器_链条-规格齐全-型号选购-非标订做-厂家批发价格-上海乙谛精密机械有限公司 | 海峰资讯 - 专注装饰公司营销型网站建设和网络营销培训 | 锂电池砂磨机|石墨烯砂磨机|碳纳米管砂磨机-常州市奥能达机械设备有限公司 | SOUNDWELL 编码器|电位器|旋转编码器|可调电位器|编码开关厂家-广东升威电子制品有限公司 | 单级/双级旋片式真空泵厂家,2xz旋片真空泵-浙江台州求精真空泵有限公司 | 经济师考试_2025中级经济师报名时间_报名入口_考试时间_华课网校经济师培训网站 | 铝箔-铝板-花纹铝板-铝型材-铝棒管-上海百亚金属材料有限公司 | 胶水,胶粘剂,AB胶,环氧胶,UV胶水,高温胶,快干胶,密封胶,结构胶,电子胶,厌氧胶,高温胶水,电子胶水-东莞聚力-聚厉胶粘 | 校服厂家,英伦校服定做工厂,园服生产定制厂商-东莞市艾咪天使校服 | 广东风淋室_广东风淋室厂家_广东风淋室价格_广州开源_传递窗_FFU-广州开源净化科技有限公司 | 沙盘模型公司_沙盘模型制作公司_建筑模型公司_工业机械模型制作厂家 | 液压压力机,液压折弯机,液压剪板机,模锻液压机-鲁南新力机床有限公司 | 压片机_高速_单冲_双层_花篮式_多功能旋转压片机-上海天九压片机厂家 | 恒温油槽-恒温水槽-低温恒温槽厂家-宁波科麦仪器有限公司 | 水质传感器_水质监测站_雨量监测站_水文监测站-山东水境传感科技有限公司 | 上海皓越真空设备有限公司官网-真空炉-真空热压烧结炉-sps放电等离子烧结炉 | 江苏皓越真空设备有限公司 | PCB设计,PCB抄板,电路板打样,PCBA加工-深圳市宏力捷电子有限公司 | 密封圈_泛塞封_格莱圈-[东莞市国昊密封圈科技有限公司]专注密封圈定制生产厂家 | 车件|铜件|车削件|车床加工|五金冲压件-PIN针,精密车件定制专业厂商【东莞品晔】 | 上海办公室装修,办公楼装修设计,办公空间设计,企业展厅设计_写艺装饰公司 | 通信天线厂家_室分八木天线_对数周期天线_天线加工厂_林创天线源头厂家 | 置顶式搅拌器-优莱博化学防爆冰箱-磁驱搅拌器-天津市布鲁克科技有限公司 | 有机废气处理-rto焚烧炉-催化燃烧设备-VOC冷凝回收装置-三梯环境 | 购买舔盐、舔砖、矿物质盐压块机,鱼饵、鱼饲料压块机--请到杜甫机械 |