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

  1. <small id='LeOV6'></small><noframes id='LeOV6'>

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

    1. <tfoot id='LeOV6'></tfoot>

      為什么 == 與 Integer.valueOf(String) 的比較對 127 和

      Why do == comparisons with Integer.valueOf(String) give different results for 127 and 128?(為什么 == 與 Integer.valueOf(String) 的比較對 127 和 128 給出不同的結果?)
          <bdo id='5vlxg'></bdo><ul id='5vlxg'></ul>
                <tbody id='5vlxg'></tbody>

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

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

                <small id='5vlxg'></small><noframes id='5vlxg'>

              1. 本文介紹了為什么 == 與 Integer.valueOf(String) 的比較對 127 和 128 給出不同的結果?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我不知道為什么這些代碼行返回不同的值:

                I have no idea why these lines of code return different values:

                System.out.println(Integer.valueOf("127")==Integer.valueOf("127"));
                System.out.println(Integer.valueOf("128")==Integer.valueOf("128"));
                System.out.println(Integer.parseInt("128")==Integer.valueOf("128"));
                

                輸出是:

                true
                false
                true
                

                為什么第一個返回true,第二個返回false?127128 之間有什么我不知道的不同之處嗎?(當然我知道127 < 128.)

                Why does the first one return true and the second one return false? Is there something different that I don't know between 127 and 128? (Of course I know that 127 < 128.)

                還有,為什么第三個返回true?

                Also, why does the third one return true?

                我已閱讀這個問題的答案,但我還是沒搞懂怎么返回true,為什么第二行的代碼返回false.

                I have read the answer of this question, but I still didn't get how it can return true, and why the code in second line returns false.

                推薦答案

                這里有一個顯著的區別.

                There's a striking difference here.

                valueOf 正在返回一個 Integer 對象,該對象的值可能緩存在 -128 和 127 之間.這就是第一個值返回 true - 它已緩存 - 第二個值返回 false - 128 不是緩存值,因此您將獲得兩個單獨的 Integer 實例.

                valueOf is returning an Integer object, which may have its values cached between -128 and 127. This is why the first value returns true - it's cached - and the second value returns false - 128 isn't a cached value, so you're getting two separate Integer instances.

                請務必注意,您將引用與 Integer#valueOf 進行比較,如果您比較的值大于緩存支持的值,它將not 評估為 true,即使解析的值是等價的(例如:Integer.valueOf(128) == Integer.valueOf(128)).您必須改用 equals().

                It is important to note that you are comparing references with Integer#valueOf, and if you are comparing a value that is larger than what the cache supports, it will not evaluate to true, even if the parsed values are equivalent (case in point: Integer.valueOf(128) == Integer.valueOf(128)). You must use equals() instead.

                parseInt 正在返回一個原始 int.這就是為什么第三個值返回 true - 128 == 128 被評估,當然是 true.

                parseInt is returning a primitive int. This is why the third value returns true - 128 == 128 is evaluated, and is of course, true.

                現在,恰好使第三個結果 true:

                Now, a fair bit happens to make that third result true:

                • 一個拆箱轉換發生在 您正在使用的等價運算符和您擁有的數據類型 - 即 intInteger.當然,您會從右側的 valueOf 獲得一個 Integer.

                • An unboxing conversion occurs with respect to the equivalence operator you're using and the datatypes you have - namely, int and Integer. You're getting an Integer from valueOf on the right hand side, of course.

                轉換后,您將比較兩個原始 int 值.比較會按照您對原語的預期進行,因此您最終會比較 128128.

                After the conversion, you're comparing two primitive int values. Comparison happens just as you would expect it to with respect to primitives, so you wind up comparing 128 and 128.

                這篇關于為什么 == 與 Integer.valueOf(String) 的比較對 127 和 128 給出不同的結果?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='sX3oG'><style id='sX3oG'><dir id='sX3oG'><q id='sX3oG'></q></dir></style></legend>

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

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

                        • 主站蜘蛛池模板: 狠狠涩 | 国产精品日日夜夜 | 久久精品国产一区二区电影 | 成人国产精品色哟哟 | 国产精品久久毛片av大全日韩 | 精品欧美一区二区三区久久久 | 日韩久久精品 | 羞羞的视频免费在线观看 | 国产精品精品 | 综合激情网 | 午夜视频免费 | 国户精品久久久久久久久久久不卡 | 国产 欧美 日韩 一区 | 欧美一二精品 | 五月天天丁香婷婷在线中 | av一区在线| 成人综合久久 | 激情91 | 欧美综合在线观看 | 超碰97免费在线 | av黄色免费 | 国产一区二区在线播放 | 久久毛片网站 | 欧美精品片| 午夜精品一区二区三区免费视频 | 国产免费视频 | 欧美日韩国产一区 | 国产精品一区免费 | 美女视频. | 国产精品1区2区 | 精品一区二区三区在线视频 | 蜜桃毛片| 久久久免费观看视频 | 亚洲欧美日韩电影 | 国产精品色哟哟网站 | 日日骚视频 | 精品欧美一区二区久久久伦 | 激情毛片 | 中文字幕在线视频网站 | 亚洲精色 | 久久五月婷 |