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

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

    1. <legend id='bV136'><style id='bV136'><dir id='bV136'><q id='bV136'></q></dir></style></legend>

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

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

        為什么相等運算符適用于整數(shù)值直到 128 數(shù)字?

        Why equal operator works for Integer value until 128 number?(為什么相等運算符適用于整數(shù)值直到 128 數(shù)字?)
          • <bdo id='1bUTN'></bdo><ul id='1bUTN'></ul>

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

            <tfoot id='1bUTN'></tfoot>
            1. <legend id='1bUTN'><style id='1bUTN'><dir id='1bUTN'><q id='1bUTN'></q></dir></style></legend>

                  <tbody id='1bUTN'></tbody>
                • <i id='1bUTN'><tr id='1bUTN'><dt id='1bUTN'><q id='1bUTN'><span id='1bUTN'><b id='1bUTN'><form id='1bUTN'><ins id='1bUTN'></ins><ul id='1bUTN'></ul><sub id='1bUTN'></sub></form><legend id='1bUTN'></legend><bdo id='1bUTN'><pre id='1bUTN'><center id='1bUTN'></center></pre></bdo></b><th id='1bUTN'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1bUTN'><tfoot id='1bUTN'></tfoot><dl id='1bUTN'><fieldset id='1bUTN'></fieldset></dl></div>
                • 本文介紹了為什么相等運算符適用于整數(shù)值直到 128 數(shù)字?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  為什么整數(shù) == 運算符不適用于 128 及之后的整數(shù)值?有人能解釋一下這種情況嗎?

                  Why Integer == operator does not work for 128 and after Integer values? Can someone explain this situation?

                  這是我的 Java 環(huán)境:

                  This is my Java environment:

                  java version "1.6.0_37"
                  Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
                  Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01, mixed mode)
                  

                  示例代碼:

                  Integer a;
                  Integer b;
                  a = 129;
                  b = 129;
                  
                  for (int i = 0; i < 200; i++) {
                      a = i;
                      b = i;
                  
                      if (a != b) {
                          System.out.println("Value:" + i + " - Different values");
                      } else {
                          System.out.println("Value:" + i + " - Same values");
                      }
                  }
                  

                  部分控制臺輸出:

                  Value:124 - Same values
                  Value:125 - Same values
                  Value:126 - Same values
                  Value:127 - Same values
                  Value:128 - Different values
                  Value:129 - Different values
                  Value:130 - Different values
                  Value:131 - Different values
                  Value:132 - Different values
                  

                  推薦答案

                  查看Integer 的源代碼 .您可以在那里看到值的緩存.

                  Check out the source code of Integer . You can see the caching of values there.

                  緩存僅在您使用 Integer.valueOf(int) 時發(fā)生,而不是在您使用 new Integer(int) 時發(fā)生.您使用的自動裝箱使用 Integer.valueOf.

                  The caching happens only if you use Integer.valueOf(int), not if you use new Integer(int). The autoboxing used by you uses Integer.valueOf.

                  根據(jù) JLS,您始終可以相信,對于介于 -128 和 127 之間的值,在自動裝箱后您會獲得相同的 Integer 對象,并且在某些實現(xiàn)中,即使對于更高的值,您也可能會獲得相同的對象.

                  According to the JLS, you can always count on the fact that for values between -128 and 127, you get the identical Integer objects after autoboxing, and on some implementations you might get identical objects even for higher values.

                  實際上在 Java 7 中(我認為在 Java 6 的較新版本中),IntegerCache 類的實現(xiàn) 已更改,上限不再是硬編碼,但可以通過屬性java.lang.Integer.IntegerCache.high"進行配置,所以如果你使用 VM 參數(shù) -Djava.lang.Integer.IntegerCache.high=1000 運行您的程序,您將獲得相同的值";所有值.

                  Actually in Java 7 (and I think in newer versions of Java 6), the implementation of the IntegerCache class has changed, and the upper bound is no longer hardcoded, but it is configurable via the property "java.lang.Integer.IntegerCache.high", so if you run your program with the VM parameter -Djava.lang.Integer.IntegerCache.high=1000, you get "Same values" for all values.

                  但是 JLS 仍然保證它只到 127:

                  But the JLS still guarantees it only until 127:

                  理想情況下,裝箱一個給定的原始值 p,總是會產(chǎn)生一個相同的引用.在實踐中,使用現(xiàn)有的實現(xiàn)技術(shù)這可能是不可行的.上述規(guī)則是一種務(wù)實的妥協(xié).上面的最后一個條款要求某些常見的值總是被裝箱到無法區(qū)分的對象中.實現(xiàn)可能會延遲或急切地緩存這些內(nèi)容.

                  Ideally, boxing a given primitive value p, would always yield an identical reference. In practice, this may not be feasible using existing implementation techniques. The rules above are a pragmatic compromise. The final clause above requires that certain common values always be boxed into indistinguishable objects. The implementation may cache these, lazily or eagerly.

                  對于其他值,此公式不允許程序員對裝箱值的身份進行任何假設(shè).這將允許(但不要求)共享部分或全部這些引用.

                  For other values, this formulation disallows any assumptions about the identity of the boxed values on the programmer's part. This would allow (but not require) sharing of some or all of these references.

                  這可確保在最常見的情況下,行為將是所需的行為,而不會造成過度的性能損失,尤其是在小型設(shè)備上.例如,內(nèi)存限制較少的實現(xiàn)可能會緩存所有字符和短整數(shù),以及 -32K - +32K 范圍內(nèi)的整數(shù)和長整數(shù).

                  This ensures that in most common cases, the behavior will be the desired one, without imposing an undue performance penalty, especially on small devices. Less memory-limited implementations might, for example, cache all characters and shorts, as well as integers and longs in the range of -32K - +32K.

                  這篇關(guān)于為什么相等運算符適用于整數(shù)值直到 128 數(shù)字?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關(guān)系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個隨機打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲為 int?)

                    <bdo id='znZlW'></bdo><ul id='znZlW'></ul>
                      <tbody id='znZlW'></tbody>

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

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

                            主站蜘蛛池模板: 91一区二区三区在线观看 | 亚洲一区二区三区视频 | 亚洲精品高清视频 | 亚洲视频一区在线 | 人妖无码 | 日日夜夜91| 91视频中文 | 伊人手机在线视频 | 免费av电影网站 | 国产韩国精品一区二区三区 | 人人干人人干人人干 | 狠狠干狠狠操 | 欧美中文字幕一区 | 亚洲欧美中文日韩在线v日本 | 成人在线观看免费 | 大久 | 婷婷色成人 | 国产精品视频一区二区三区 | av免费网站在线观看 | 亚洲小说图片 | 一区二区三区在线免费观看 | 成人不卡视频 | 亚洲综合天堂网 | 韩日av片| 亚洲欧美中文日韩在线v日本 | 中文字幕亚洲一区二区三区 | 天堂中文在线观看 | 欧美视频一区 | 国产视频一区二区三区四区五区 | 欧美综合国产精品久久丁香 | 精品久久久久久久久久久下田 | 欧美日韩三区 | 噜噜噜噜狠狠狠7777视频 | 日韩精品二区 | 精品成人免费视频 | 国产日韩欧美一区 | 99国产精品久久久久老师 | 国产免费一区二区三区免费视频 | 日韩精品一区二区三区中文字幕 | 特一级毛片| 亚洲精品视频三区 |