久久久久久久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)系嗎?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

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

                  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)存,所以我猜它會(huì)稍微降低性能?但另一方面,它使內(nèi)容更清晰,尤其是當(dāng) int/string 是一個(gè)長計(jì)算時(shí).

                  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

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

                  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.


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


                  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:

                  聲明一個(gè)變量只是為了立即返回或拋出它是一個(gè)錯(cuò)誤練習(xí).一些開發(fā)人員認(rèn)為這種做法改進(jìn)了代碼可讀性,因?yàn)樗顾麄兡軌蛎鞔_地命名正在發(fā)生的事情回.但是,此變量是內(nèi)部實(shí)現(xiàn)細(xì)節(jié)不會(huì)暴露給方法的調(diào)用者.方法名應(yīng)該足以讓來電者確切知道會(huì)發(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

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

                  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 在他的評(píng)論中提到的那樣,JIT 很可能會(huì)內(nèi)聯(lián)變量,無論哪種方式,您最終都會(huì)得到相同的結(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)建一個(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?)
                  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. 主站蜘蛛池模板: 爱爱免费视频 | 凹凸日日摸日日碰夜夜 | 古装三级在线播放 | 天天躁日日躁性色aⅴ电影 免费在线观看成年人视频 国产欧美精品 | 日韩一区二区在线播放 | 亚洲精品国产成人 | 96国产精品久久久久aⅴ四区 | 久久a久久| 操操日 | 欧美精品福利视频 | 高清视频一区二区三区 | 欧美1区2区| 久久国产精品久久国产精品 | 成人精品鲁一区一区二区 | 国产精品久久国产精品 | 婷婷综合五月天 | 一区二区三区免费在线观看 | 精品伦精品一区二区三区视频 | 97精品久久| 亚洲国产aⅴ成人精品无吗 亚洲精品久久久一区二区三区 | 欧美日韩在线成人 | 91手机精品视频 | 久久噜噜噜精品国产亚洲综合 | 国产精品久久久久久妇女6080 | 日韩在线免费 | 日韩免费网 | 毛片a级| 国外激情av| 中文字幕动漫成人 | 欧美性猛交一区二区三区精品 | 99国产精品一区二区三区 | 中文字幕一区二区三区四区五区 | 欧美1区 | 免费av毛片 | 免费在线一区二区三区 | 最新91在线 | 99精品亚洲国产精品久久不卡 | 日韩精品免费一区 | 久久久久久高清 | 久久中文字幕电影 | 日本黄色高清视频 |