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

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

        <tfoot id='vn6IY'></tfoot>
      1. <small id='vn6IY'></small><noframes id='vn6IY'>

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

        為什么在比較 Java 中的整數包裝器時 128==128 為假

        Why is 128==128 false but 127==127 is true when comparing Integer wrappers in Java?(為什么在比較 Java 中的整數包裝器時 128==128 為假但 127==127 為真?)

            <bdo id='1klFo'></bdo><ul id='1klFo'></ul>
                <tbody id='1klFo'></tbody>

              <i id='1klFo'><tr id='1klFo'><dt id='1klFo'><q id='1klFo'><span id='1klFo'><b id='1klFo'><form id='1klFo'><ins id='1klFo'></ins><ul id='1klFo'></ul><sub id='1klFo'></sub></form><legend id='1klFo'></legend><bdo id='1klFo'><pre id='1klFo'><center id='1klFo'></center></pre></bdo></b><th id='1klFo'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1klFo'><tfoot id='1klFo'></tfoot><dl id='1klFo'><fieldset id='1klFo'></fieldset></dl></div>

              <small id='1klFo'></small><noframes id='1klFo'>

                  <tfoot id='1klFo'></tfoot>
                  <legend id='1klFo'><style id='1klFo'><dir id='1klFo'><q id='1klFo'></q></dir></style></legend>
                1. 本文介紹了為什么在比較 Java 中的整數包裝器時 128==128 為假但 127==127 為真?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  class D {
                      public static void main(String args[]) {
                          Integer b2=128;
                          Integer b3=128;
                          System.out.println(b2==b3);
                      }
                  }
                  

                  輸出:

                  false
                  

                  <小時>

                  class D {
                      public static void main(String args[]) {
                          Integer b2=127;
                          Integer b3=127;
                          System.out.println(b2==b3);
                      }
                  }
                  

                  輸出:

                  true
                  

                  注意:-128 到 127 之間的數字為真.

                  Note: Numbers between -128 and 127 are true.

                  推薦答案

                  當您在 Java 中編譯數字文字并將其分配給整數(大寫 I)時,編譯器會發出:

                  When you compile a number literal in Java and assign it to a Integer (capital I) the compiler emits:

                  Integer b2 =Integer.valueOf(127)
                  

                  這行代碼也是在你使用自動裝箱的時候生成的.

                  This line of code is also generated when you use autoboxing.

                  valueOf 的實現使得某些數字被池化",它為小于 128 的值返回相同的實例.

                  valueOf is implemented such that certain numbers are "pooled", and it returns the same instance for values smaller than 128.

                  來自 java 1.6 源代碼,第 621 行:

                  From the java 1.6 source code, line 621:

                  public static Integer valueOf(int i) {
                      if(i >= -128 && i <= IntegerCache.high)
                          return IntegerCache.cache[i + 128];
                      else
                          return new Integer(i);
                  }
                  

                  high的值可以通過系統屬性配置為另一個值.

                  The value of high can be configured to another value, with the system property.

                  -Djava.lang.Integer.IntegerCache.high=999

                  -Djava.lang.Integer.IntegerCache.high=999

                  如果您使用該系統屬性運行程序,它將輸出 true!

                  If you run your program with that system property, it will output true!

                  顯而易見的結論:永遠不要依賴兩個引用是相同的,總是用 .equals() 方法比較它們.

                  The obvious conclusion: never rely on two references being identical, always compare them with .equals() method.

                  所以 b2.equals(b3) 將為 b2,b3 的所有邏輯相等值打印 true.

                  So b2.equals(b3) will print true for all logically equal values of b2,b3.

                  請注意,Integer 緩存不是出于性能原因,而是為了符合 JLS,第 5.1.7 節;必須為值 -128 到 127(含)提供對象標識.

                  Note that Integer cache is not there for performance reasons, but rather to conform to the JLS, section 5.1.7; object identity must be given for values -128 to 127 inclusive.

                  Integer#valueOf(int) 也記錄了這種行為:

                  通過緩存頻繁請求的值,此方法可能會顯著提高空間和時間性能.此方法將始終緩存 -128 到 127(含)范圍內的值,并可能緩存此范圍之外的其他值.

                  this method is likely to yield significantly better space and time performance by caching frequently requested values. This method will always cache values in the range -128 to 127, inclusive, and may cache other values outside of this range.

                  這篇關于為什么在比較 Java 中的整數包裝器時 128==128 為假但 127==127 為真?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?)
                  <i id='WSNMc'><tr id='WSNMc'><dt id='WSNMc'><q id='WSNMc'><span id='WSNMc'><b id='WSNMc'><form id='WSNMc'><ins id='WSNMc'></ins><ul id='WSNMc'></ul><sub id='WSNMc'></sub></form><legend id='WSNMc'></legend><bdo id='WSNMc'><pre id='WSNMc'><center id='WSNMc'></center></pre></bdo></b><th id='WSNMc'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='WSNMc'><tfoot id='WSNMc'></tfoot><dl id='WSNMc'><fieldset id='WSNMc'></fieldset></dl></div>

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

                          <bdo id='WSNMc'></bdo><ul id='WSNMc'></ul>

                              <tbody id='WSNMc'></tbody>
                            <tfoot id='WSNMc'></tfoot>
                            <legend id='WSNMc'><style id='WSNMc'><dir id='WSNMc'><q id='WSNMc'></q></dir></style></legend>
                            主站蜘蛛池模板: 日韩精品一区二区三区中文在线 | 欧美激情在线精品一区二区三区 | 亚洲一区二区网站 | 99pao成人国产永久免费视频 | 国产成人91| 毛片一级片 | 国产在线97 | 国产精品一区二区久久精品爱微奶 | 欧美freesex黑人又粗又大 | 日韩色图在线观看 | japan25hdxxxx日本| www网站在线观看 | 夜夜夜夜夜夜曰天天天 | 亚洲天堂一区二区 | 国产精品一区在线播放 | 免费观看的av毛片的网站 | 国产一区二区三区在线 | 精品一区二区在线观看 | 一级黄色av电影 | 国产人成精品一区二区三 | 国产福利视频 | av在线免费观看不卡 | 欧美日韩高清免费 | 一区二区三区观看视频 | 成人在线小视频 | 91伊人网| 免费国产精品久久久久久 | 国产免费看 | 成人毛片视频免费 | 久久久青草 | 手机av免费在线 | 天天躁日日躁狠狠的躁天龙影院 | 国产中文字幕网 | 欧美黄色大片在线观看 | 国内精品视频免费观看 | 精品久久影院 | 亚洲视频国产视频 | 中文字幕av在线 | 欧美v免费 | 91免费小视频 | 久久88|