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

    <tfoot id='EDroR'></tfoot>
    <legend id='EDroR'><style id='EDroR'><dir id='EDroR'><q id='EDroR'></q></dir></style></legend>

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

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

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

        new Integer(123)、Integer.valueOf(123) 和 just 123 之間的區(qū)

        Differences between new Integer(123), Integer.valueOf(123) and just 123(new Integer(123)、Integer.valueOf(123) 和 just 123 之間的區(qū)別)
          <i id='jZ0tW'><tr id='jZ0tW'><dt id='jZ0tW'><q id='jZ0tW'><span id='jZ0tW'><b id='jZ0tW'><form id='jZ0tW'><ins id='jZ0tW'></ins><ul id='jZ0tW'></ul><sub id='jZ0tW'></sub></form><legend id='jZ0tW'></legend><bdo id='jZ0tW'><pre id='jZ0tW'><center id='jZ0tW'></center></pre></bdo></b><th id='jZ0tW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jZ0tW'><tfoot id='jZ0tW'></tfoot><dl id='jZ0tW'><fieldset id='jZ0tW'></fieldset></dl></div>

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

            <legend id='jZ0tW'><style id='jZ0tW'><dir id='jZ0tW'><q id='jZ0tW'></q></dir></style></legend>
          • <tfoot id='jZ0tW'></tfoot>

              <bdo id='jZ0tW'></bdo><ul id='jZ0tW'></ul>
                <tbody id='jZ0tW'></tbody>
                  本文介紹了new Integer(123)、Integer.valueOf(123) 和 just 123 之間的區(qū)別的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  最近我看到這樣的代碼(Java):

                  Recenlty I saw code (Java) like this:

                  myMethod(new Integer(123));
                  

                  我目前正在重構(gòu)一些代碼,Sonar 工具中有一個(gè)提示,使用這樣的東西對(duì)內(nèi)存更友好:

                  I am currently refactoring some code, and there is a tip in Sonar tool, that it's more memory friendly to use sth like this:

                  myMethod(Integer.valueOf(123));
                  

                  但是在這種情況下,我認(rèn)為如果我會(huì)使用沒有區(qū)別:

                  However in this case, I think that there is no difference if I would use:

                  myMethod(123);
                  

                  我可以理解,如果我將變量傳遞給方法,但硬編碼 int?或者如果會(huì)有 Long/Double 等,我想要 Long 表示數(shù)字.但是整數(shù)?

                  I could understand that, if I would pass a variable to the method, but hard coded int? Or if there would be Long/Double etc and I want Long representation of number. But integer?

                  推薦答案

                  new Integer(123) 將為每個(gè)調(diào)用創(chuàng)建一個(gè)新的 Object 實(shí)例.

                  new Integer(123) will create a new Object instance for each call.

                  根據(jù) javadoc, Integer.valueOf(123) 不同之處在于它緩存對(duì)象......所以如果你調(diào)用它更多,你可能(或可能不會(huì))最終得到相同的 Object不止一次.

                  According to the javadoc, Integer.valueOf(123) has the difference it caches Objects... so you may (or may not) end up with the same Object if you call it more than once.

                  比如下面的代碼:

                     public static void main(String[] args) {
                  
                          Integer a = new Integer(1);
                          Integer b = new Integer(1);
                  
                          System.out.println("a==b? " + (a==b));
                  
                          Integer c = Integer.valueOf(1);
                          Integer d = Integer.valueOf(1);
                  
                          System.out.println("c==d? " + (c==d));
                  
                      }
                  

                  有以下輸出:

                  a==b? false
                  c==d? true
                  

                  至于使用 int 值,您使用的是原始類型(考慮到您的方法也在其簽名上使用原始類型) - 它會(huì)使用更少的內(nèi)存并且可能更快,但是您例如,不能將其添加到收藏中.

                  As to using the int value, you are using the primitive type (considering your method also uses the primitive type on its signature) - it will use slightly less memory and might be faster, but you won't be ale to add it to collections, for instance.

                  如果您的方法的簽名,還請(qǐng)查看 Java 的 AutoBoxing使用 Integer - 使用時(shí),JVM 會(huì)自動(dòng)為您調(diào)用 Integer.valueOf()(因此也使用緩存).

                  Also take a look at Java's AutoBoxing if your method's signature uses Integer- when using it, the JVM will automatically call Integer.valueOf() for you (therefore using the cache aswell).

                  這篇關(guān)于new Integer(123)、Integer.valueOf(123) 和 just 123 之間的區(qū)別的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測(cè) 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ù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲(chǔ)為 int?)

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

                            <tbody id='5HEg4'></tbody>
                            <bdo id='5HEg4'></bdo><ul id='5HEg4'></ul>
                            <tfoot id='5HEg4'></tfoot>

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

                            主站蜘蛛池模板: 国产乱码精品一区二区三区中文 | 丁香综合| 久久久毛片 | 日韩在线免费 | 午夜爱爱网 | 日韩av大片免费看 | 91久久国产综合久久 | 欧美激情精品久久久久久免费 | 中文成人在线 | 亚洲欧美中文日韩在线v日本 | 日韩精品一区二区三区在线播放 | 日韩高清av | 一区二区三区四区不卡视频 | 国产精品久久久久无码av | 亚洲精品乱码久久久久久按摩观 | 中文字幕在线免费视频 | 亚洲经典一区 | 三级在线观看 | 亚洲视频一区在线观看 | 欧美日韩一本 | 四虎影院欧美 | 一区精品国产欧美在线 | www.av7788.com | 91一区二区三区在线观看 | 欧美中文字幕在线观看 | 国内在线视频 | 天堂三级| 亚洲一区视频在线 | 人人干超碰| 九色.com | 欧美一区2区三区4区公司 | 久久成人久久 | 日本久久久久久 | 一区二区三区视频在线 | 91社区在线观看高清 | 久久av一区二区 | 久草a√| 精品在线一区二区三区 | 日韩视频一区二区三区 | 欧美精品一区二区免费视频 | 视频在线观看一区二区 |