久久久久久久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>
                            主站蜘蛛池模板: 国产高清自拍视频在线观看 | 一区二区国产在线观看 | 亚洲综合日韩精品欧美综合区 | 久久99精品久久久久久国产越南 | 久久久久久国产一区二区三区 | 国产一区二区三区免费观看在线 | 亚洲一区二区电影在线观看 | 久久精品国产99国产 | 在线观看亚洲精品 | 在线看91 | 亚洲一区二区三区在线视频 | 欧美成年人网站 | 亚洲综合在线视频 | 免费一级黄色电影 | 欧美激情精品久久久久久 | www.操.com | 成人深夜福利网站 | 日本久草 | 看羞羞视频 | 第四色播日韩第一页 | 国产高清性xxxxxxxx | 免费h在线 | 日韩在线看片 | 美女久久久久 | 日韩有码在线播放 | 亚洲欧洲精品一区 | 人人看人人爽 | 国产精品久久久久久久久久三级 | 欧美综合视频在线 | 国产精品久久久久无码av | 日韩精品| 成人亚洲性情网站www在线观看 | 欧美成人a∨高清免费观看 欧美日韩中 | 婷婷综合激情 | 欧美精品日韩精品 | 久久久综合 | 好姑娘影视在线观看高清 | 午夜三级在线观看 | 婷婷久久一区 | 国产夜恋视频在线观看 | 日韩 国产 在线 |