久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" 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>

                          主站蜘蛛池模板: 欧美日韩中文在线观看 | xx性欧美肥妇精品久久久久久 | 国产精品福利视频 | 一区二区三区电影网 | 亚洲精品乱码久久久久久按摩观 | 精品久久久久久亚洲精品 | 精精国产xxxx视频在线 | 操久久久| 在线日韩欧美 | 欧美在线综合 | 国产精品久久久久久久久免费相片 | 狠狠艹| 亚洲国产aⅴ成人精品无吗 国产精品永久在线观看 | av手机在线免费观看 | 色伊人久久| 日韩一区二区av | 国产免费一区 | 亚洲欧美国产精品久久 | 国产91久久精品一区二区 | 婷婷在线视频 | 亚洲国产高清高潮精品美女 | 欧美成人精品一区二区男人看 | 香蕉一区 | 日韩一区在线观看视频 | 99久久国产免费 | 日本不卡一区 | 国产小视频自拍 | 午夜免费观看体验区 | 99热99| 久久91精品国产 | 精品亚洲一区二区 | 最新av在线播放 | 妹子干综合 | 91国内外精品自在线播放 | 久久福利电影 | 91精品国产一区二区三区 | 国产精品一区二区三区四区 | 91久久| 国产小视频在线观看 | 成人精品一区二区 | 一区二区三区av |