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

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

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

        • <bdo id='KliPk'></bdo><ul id='KliPk'></ul>

        Java:整數(shù)等于 vs. ==

        Java: Integer equals vs. ==(Java:整數(shù)等于 vs. ==)
          <tbody id='unonn'></tbody>

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

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

                  本文介紹了Java:整數(shù)等于 vs. ==的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  從 Java 1.5 開始,您幾乎可以在許多情況下將 Integerint 互換.

                  As of Java 1.5, you can pretty much interchange Integer with int in many situations.

                  但是,我發(fā)現(xiàn)我的代碼中有一個潛在的缺陷,這讓我有點吃驚.

                  However, I found a potential defect in my code that surprised me a bit.

                  以下代碼:

                  Integer cdiCt = ...;
                  Integer cdsCt = ...;
                  ...
                  if (cdiCt != null && cdsCt != null && cdiCt != cdsCt)
                      mismatch = true;
                  

                  當值相等時,似乎錯誤地設置了不匹配,盡管我無法確定在什么情況下.我在 Eclipse 中設置了一個斷點,發(fā)現(xiàn) Integer 的值都是 137,我檢查了布爾表達式,它說它是假的,但是當我越過它時,它將不匹配設置為真.

                  appeared to be incorrectly setting mismatch when the values were equal, although I can't determine under what circumstances. I set a breakpoint in Eclipse and saw that the Integer values were both 137, and I inspected the boolean expression and it said it was false, but when I stepped over it, it was setting mismatch to true.

                  將條件更改為:

                  if (cdiCt != null && cdsCt != null && !cdiCt.equals(cdsCt))
                  

                  解決了問題.

                  誰能解釋一下為什么會這樣?到目前為止,我只在我自己的 PC 上的本地主機上看到了這種行為.在這種特殊情況下,代碼成功通過了大約 20 次比較,但在 2 次比較失敗.問題始終可以重現(xiàn).

                  Can anyone shed some light on why this happened? So far, I have only seen the behavior on my localhost on my own PC. In this particular case, the code successfully made it past about 20 comparisons, but failed on 2. The problem was consistently reproducible.

                  如果這是一個普遍存在的問題,它應該會導致我們的其他環(huán)境(開發(fā)和測試)出現(xiàn)錯誤,但到目前為止,在執(zhí)行此代碼片段的數(shù)百次測試之后,沒有人報告此問題.

                  If it is a prevalent problem, it should be causing errors on our other environments (dev and test), but so far, no one has reported the problem after hundreds of tests executing this code snippet.

                  使用 == 比較兩個 Integer 值仍然不合法嗎?

                  Is it still not legitimate to use == to compare two Integer values?

                  除了下面所有的好答案之外,下面的 stackoverflow 鏈接還有很多額外的信息.它實際上會回答我原來的問題,但是因為我沒有在我的問題中提到自動裝箱,所以它沒有出現(xiàn)在選定的建議中:

                  In addition to all the fine answers below, the following stackoverflow link has quite a bit of additional information. It actually would have answered my original question, but because I didn't mention autoboxing in my question, it didn't show up in the selected suggestions:

                  為什么編譯器/JVM就不能讓自動裝箱正常工作"?

                  推薦答案

                  JVM 正在緩存整數(shù)值.因此,與 == 的比較僅適用于 -128 到 127 之間的數(shù)字.

                  The JVM is caching Integer values. Hence the comparison with == only works for numbers between -128 and 127.

                  參考:#Immutable_Objects_.2F_Wrapper_Class_Caching

                  這篇關于Java:整數(shù)等于 vs. ==的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關文檔推薦

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

                    <tbody id='trNIQ'></tbody>

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

                      • <bdo id='trNIQ'></bdo><ul id='trNIQ'></ul>
                            <legend id='trNIQ'><style id='trNIQ'><dir id='trNIQ'><q id='trNIQ'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 日韩欧美国产一区二区三区 | 国产精品夜夜夜一区二区三区尤 | 久久久国产一区二区三区四区小说 | 91亚洲精品久久久电影 | 91精品久久久 | 99re在线视频 | 91日日| 美女三区 | 日韩精品在线观看网站 | 亚洲国产精品一区二区久久 | 久久久久国产一区二区三区四区 | 国产精品久久久久久久免费大片 | 国产一级在线观看 | 91电影| 亚州精品成人 | 在线免费看黄 | 成人久久一区 | 精品久久av| 国产一区二区欧美 | 激情91| 欧美激情 亚洲 | 人人做人人澡人人爽欧美 | 亚洲精品久久久蜜桃 | 西西裸体做爰视频 | 国产精品久久久久久久久久久免费看 | 久久爱一区 | av电影一区二区 | 国产精品一区二区视频 | 精品在线播放 | 免费毛片网站在线观看 | 成人免费黄视频 | 亚洲成人免费 | 国产精品18久久久久久白浆动漫 | 亚洲一区二区三区免费在线观看 | 国产成人一区二区三区久久久 | 韩国成人在线视频 | 日韩一区二区在线视频 | 一级视频在线免费观看 | 亚洲一区在线免费观看 | 日韩欧美在线视频播放 | 综合精品久久久 |