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

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

  • <small id='2nasR'></small><noframes id='2nasR'>

      <tfoot id='2nasR'></tfoot>

      • <bdo id='2nasR'></bdo><ul id='2nasR'></ul>
      1. <legend id='2nasR'><style id='2nasR'><dir id='2nasR'><q id='2nasR'></q></dir></style></legend>
      2. java的行為不一致==

        Inconsistent behavior on java#39;s ==(java的行為不一致==)
        <i id='vUSFQ'><tr id='vUSFQ'><dt id='vUSFQ'><q id='vUSFQ'><span id='vUSFQ'><b id='vUSFQ'><form id='vUSFQ'><ins id='vUSFQ'></ins><ul id='vUSFQ'></ul><sub id='vUSFQ'></sub></form><legend id='vUSFQ'></legend><bdo id='vUSFQ'><pre id='vUSFQ'><center id='vUSFQ'></center></pre></bdo></b><th id='vUSFQ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vUSFQ'><tfoot id='vUSFQ'></tfoot><dl id='vUSFQ'><fieldset id='vUSFQ'></fieldset></dl></div>
        <tfoot id='vUSFQ'></tfoot>

            <tbody id='vUSFQ'></tbody>
        • <small id='vUSFQ'></small><noframes id='vUSFQ'>

                <legend id='vUSFQ'><style id='vUSFQ'><dir id='vUSFQ'><q id='vUSFQ'></q></dir></style></legend>

                  <bdo id='vUSFQ'></bdo><ul id='vUSFQ'></ul>
                • 本文介紹了java的行為不一致==的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  考慮這段代碼:

                  class test {
                     public static void main(String[] args) {
                        test inst_test = new test();
                        int i1 = 2000;
                        int i2 = 2000;
                        int i3 = 2;
                        int i4 = 2;
                        Integer Ithree = new Integer(2); // 1
                        Integer Ifour = new Integer(2); // 2
                        System.out.println( Ithree == Ifour );
                        inst_test.method( i3 , i4 );
                        inst_test.method( i1 , i2 );
                     }
                     public void method( Integer i , Integer eye ) {
                        System.out.println(i == eye );
                     }
                  }
                  

                  打印出來:

                  false
                  true
                  false
                  

                  我理解第一個(gè) false,== 運(yùn)算符只檢查兩個(gè)引用是否在同一個(gè)對象上工作,在這種情況下不是.

                  I understand the first false, the == operator only checks if two references are working on the same object, which in this case aren't.

                  下面的 truefalse 讓我摸不著頭腦.為什么 Java 會(huì)認(rèn)為 i3i4 相等但 i1i2 不同?兩者都被包裝成整數(shù),不應(yīng)該 both 評(píng)估為假嗎?這種不一致是否有實(shí)際原因?

                  The following true and false have me scratching my head. Why would Java consider i3 and i4 equal but i1 and i2 different? Both have been wrapped to Integer, shouldn't both evaluate to false? Is there a practical reason for this inconsistency?

                  推薦答案

                  將基元自動(dòng)裝箱到對象中(在您對 method 的調(diào)用中使用的方法是使用小值緩存.來自 Java 語言規(guī)范第 5.1.7 節(jié):

                  Autoboxing of primitives into objects (as used in your calls to method uses a cache of small values. From the Java Language Specification section 5.1.7:

                  如果被裝箱的值p為真,false,一個(gè)字節(jié),一個(gè)字符在范圍內(nèi)u0000 到 u007f,或者一個(gè) int 或 short介于 -128 和 127 之間的數(shù)字,然后讓r1 和 r2 是任意兩個(gè)的結(jié)果p的拳擊轉(zhuǎn)換.它總是r1 == r2 的情況.

                  If the value p being boxed is true, false, a byte, a char in the range u0000 to u007f, or an int or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2.

                  緊隨其后的規(guī)范討論部分也很有趣.值得注意的是,如果 JVM 愿意,它可以緩存 更多 值 - 你不能確定這樣做的結(jié)果:

                  The discussion part of the spec immediately following that is interesting too. Notably a JVM can cache more values if it wants to - you can't be sure of the results of doing:

                  Integer i1 = 129;
                  Integer i2 = 129;
                  boolean b = (i1 == i2);
                  

                  這篇關(guān)于java的行為不一致==的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)建一個(gè)隨機(jī)打亂數(shù)字的 int 數(shù)組)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲(chǔ)為 int?)
                  Unexpected result in long/int division(意外結(jié)果導(dǎo)致長/整數(shù)除法)
                  <i id='4nGTx'><tr id='4nGTx'><dt id='4nGTx'><q id='4nGTx'><span id='4nGTx'><b id='4nGTx'><form id='4nGTx'><ins id='4nGTx'></ins><ul id='4nGTx'></ul><sub id='4nGTx'></sub></form><legend id='4nGTx'></legend><bdo id='4nGTx'><pre id='4nGTx'><center id='4nGTx'></center></pre></bdo></b><th id='4nGTx'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4nGTx'><tfoot id='4nGTx'></tfoot><dl id='4nGTx'><fieldset id='4nGTx'></fieldset></dl></div>
                  • <bdo id='4nGTx'></bdo><ul id='4nGTx'></ul>
                    <legend id='4nGTx'><style id='4nGTx'><dir id='4nGTx'><q id='4nGTx'></q></dir></style></legend>
                      <tbody id='4nGTx'></tbody>

                        • <small id='4nGTx'></small><noframes id='4nGTx'>

                          <tfoot id='4nGTx'></tfoot>
                            主站蜘蛛池模板: 精品国产欧美一区二区三区成人 | 羞羞网站免费 | 一级黄色片免费在线观看 | 欧美视频一区 | 亚洲一区二区免费看 | 久久免费视频观看 | 福利片一区二区 | 精品视频成人 | 欧美成人一区二区三区 | 欧美爱爱视频网站 | 户外露出一区二区三区 | 国产精品五月天 | 日韩视频 中文字幕 | 日本一区高清 | 国产精品日韩 | 国产视频精品区 | 中文字幕视频三区 | 成人网视频 | 久久免费福利 | 欧美一区二区黄 | 久久国产一区二区三区 | 一级毛片在线播放 | 国产乱码高清区二区三区在线 | 亚洲成av | 亚洲少妇综合网 | 日韩国产中文字幕 | 欧美精品综合在线 | 午夜国产羞羞视频免费网站 | 亚洲色图插插插 | 一区视频在线免费观看 | 成人性生交大片免费看中文带字幕 | 国产欧美日韩精品一区二区三区 | yiren22综合网成人 | 国产精品成人一区二区三区夜夜夜 | 日本精品久久久久久久 | 精品综合久久久 | 久久精品在线播放 | 免费观看www | 欧美精品中文字幕久久二区 | 久久国产成人 | 欧美精品一区久久 |