久久久久久久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 語句之前的局部變量,這有關系嗎?

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

        <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 語句之前的局部變量,這有關系嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

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

                  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;
                  

                  我知道整數使用內存,所以我猜它會稍微降低性能?但另一方面,它使內容更清晰,尤其是當 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 還多,那么了解這一點也很重要IntelliJ 在 Kotlin 中也對此進行了檢查:

                  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:

                  變量只在后面的返回中使用,應該被內聯

                  Variable used only in following return and should be inlined

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

                  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 規則,稱為 返回之前的不必要的本地,談論這個.它說:


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

                  避免不必要地創建局部變量.

                  Avoid unnecessarily creating local variables.

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

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

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

                  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:

                  變量只在后面的返回中使用,可以內聯

                  Variable used only in following return and can be inlined

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

                  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.


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


                  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.

                  這篇關于return 語句之前的局部變量,這有關系嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  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?)
                  Unexpected result in long/int division(意外結果導致長/整數除法)
                        <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. 主站蜘蛛池模板: 日韩超碰在线 | 亚洲一区二区三区在线 | 国产乱码精品一品二品 | 欧美日韩在线播放 | 亚洲精品国产一区 | 免费看91 | 日本人和亚洲人zjzjhd | 国产欧美在线 | 青青草综合网 | 欧美日韩国产高清 | 在线观看国产精品视频 | 一区二区免费在线 | 欧美一区二| 免费看黄色视屏 | 国产在线观看一区二区三区 | 日日骚av | 欧美一区二区三区视频 | 黄色91在线 | 亚洲精品一区二区三区蜜桃久 | h片在线播放 | 国产中文字幕网 | 亚洲免费在线播放 | 午夜免费在线 | 免费一看一级毛片 | 在线观看国产三级 | 欧美在线亚洲 | 精品久久久久久久久久久久 | 日本在线免费看最新的电影 | 在线激情视频 | 久久精品国产亚洲一区二区 | 少妇一区二区三区 | 亚洲精品乱码久久久久久蜜桃91 | 欧美精品成人一区二区三区四区 | 天天综合网天天综合色 | 免费特级黄毛片 | 夜夜操av| 免费在线日韩 | 久久久av | 亚洲精品一区国语对白 | 国产精品99999999 | 亚洲va国产日韩欧美精品色婷婷 |