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

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

    <tfoot id='3HqrW'></tfoot>
    1. <legend id='3HqrW'><style id='3HqrW'><dir id='3HqrW'><q id='3HqrW'></q></dir></style></legend>
      • <bdo id='3HqrW'></bdo><ul id='3HqrW'></ul>
    2. <small id='3HqrW'></small><noframes id='3HqrW'>

        return 語句之前的局部變量,這有關(guān)系嗎?

        Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關(guān)系嗎?)

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

                2. 本文介紹了return 語句之前的局部變量,這有關(guān)系嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  對不起,如果這是一個新手問題,但我找不到答案.這樣做更好嗎:

                  Sorry if this is a newbie question but I couldn't find an answer for this. Is it better to do this:

                  int result = number/number2;
                  return result;
                  

                  或:

                  return number/number2;
                  

                  我知道整數(shù)使用內(nèi)存,所以我猜它會稍微降低性能?但另一方面,它使內(nèi)容更清晰,尤其是當(dāng) int/string 是一個長計算時.

                  I know integers use memory so I'm guessing it will slightly decrease performance? But on the other hand it makes stuff clearer, especially when the int/string is a long calculation.

                  推薦答案

                  如果像我一樣,您使用的 Kotlin 比 Java 還多,那么了解這一點(diǎn)也很重要IntelliJ 在 Kotlin 中也對此進(jìn)行了檢查:

                  if, like me, you've been using more Kotlin than Java, it'd also be relevant to know that IntelliJ also has an inspection for this in Kotlin:

                  變量只在后面的返回中使用,應(yīng)該被內(nèi)聯(lián)

                  Variable used only in following return and should be inlined

                  此檢查報告僅在下一個 return 語句中使用的局部變量或其他變量的精確副本.在這兩種情況下,最好內(nèi)聯(lián)這樣一個變量.

                  This inspection reports local variables either used only in the very next return statement or exact copies of other variables. In both cases it's better to inline such a variable.


                  實際上有一個從 PMD 繼承的 SonarQube 規(guī)則,稱為 返回之前的不必要的本地,談?wù)撨@個.它說:


                  There is actually a SonarQube rule inherited from PMD called Unnecessary Local Before Return that talks about this. It says:

                  避免不必要地創(chuàng)建局部變量.

                  Avoid unnecessarily creating local variables.

                  此規(guī)則后來被 SSLR 規(guī)則替換不應(yīng)聲明變量然后立即返回或拋出,保持相同的位置:

                  This rule was later replaced by SSLR rule Variables should not be declared and then immediately returned or thrown, which maintains the same position:

                  聲明一個變量只是為了立即返回或拋出它是一個錯誤練習(xí).一些開發(fā)人員認(rèn)為這種做法改進(jìn)了代碼可讀性,因為它使他們能夠明確地命名正在發(fā)生的事情回.但是,此變量是內(nèi)部實現(xiàn)細(xì)節(jié)不會暴露給方法的調(diào)用者.方法名應(yīng)該足以讓來電者確切知道會發(fā)生什么返回.

                  Declaring a variable only to immediately return or throw it is a bad practice. Some developers argue that the practice improves code readability, because it enables them to explicitly name what is being returned. However, this variable is an internal implementation detail that is not exposed to the callers of the method. The method name should be sufficient for callers to know exactly what will be returned.

                  我完全同意.

                  IntelliJ(或至少是 Android Studio)也有針對這種情況的警告:

                  IntelliJ (or at least Android Studio) also has a warning for this situation:

                  變量只在后面的返回中使用,可以內(nèi)聯(lián)

                  Variable used only in following return and can be inlined

                  此檢查報告僅在下一次返回中使用的局部變量或其他變量的精確副本.在這兩種情況下,最好內(nèi)聯(lián)這樣一個變量.

                  This inspection reports local variables either used only in the very next return or exact copies of other variables. In both cases it's better to inline such a variable.


                  我認(rèn)為在這種情況下根本不需要擔(dān)心性能問題.話雖如此,正如@Clashsoft 在他的評論中提到的那樣,JIT 很可能會內(nèi)聯(lián)變量,無論哪種方式,您最終都會得到相同的結(jié)果.


                  I don't think performance is something to worry about at all in this situation. That being said, as @Clashsoft mentioned in his comment, the JIT will most likely inline the variable and you'll end up with the same result either way.

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

                        <tfoot id='x3D7a'></tfoot>
                          <bdo id='x3D7a'></bdo><ul id='x3D7a'></ul>
                          <legend id='x3D7a'><style id='x3D7a'><dir id='x3D7a'><q id='x3D7a'></q></dir></style></legend>

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

                          2. 主站蜘蛛池模板: 久久亚洲综合 | 久久综合九色综合欧美狠狠 | 狠狠躁18三区二区一区 | 欧美a级成人淫片免费看 | 男人的天堂久久 | 国产毛片av | 欧洲一级黄 | 日本不卡一区二区三区在线观看 | 亚洲国产精品一区二区久久 | 欧美一级久久 | 密乳av| 亚洲欧美中文日韩在线v日本 | 天天爽夜夜操 | 成人福利在线观看 | 亚洲精品国产综合区久久久久久久 | 亚洲国产精品一区二区第一页 | 黄色大片免费播放 | 夜夜爽99久久国产综合精品女不卡 | 日韩高清一区二区 | 欧美日韩国产在线 | 久久精品av麻豆的观看方式 | 一区二区三区免费 | 亚洲成人黄色 | 大象视频一区二区 | 国产精品久久久久久久久免费樱桃 | 自拍偷拍av| 欧美精品在欧美一区二区 | 国产精品免费看 | 国内精品视频免费观看 | 国产欧美日韩精品一区二区三区 | av中文字幕在线观看 | 欧美精品二区 | 日韩精品亚洲专区在线观看 | 亚洲精品成人在线 | 欧美激情一区二区三级高清视频 | 亚洲视频免费播放 | 一区二区三区在线 | 国产一二三视频在线观看 | 久久精品久久综合 | 国产精品一区二区免费 | 色频|