<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### [短路](https://lingcoder.gitee.io/onjava8/#/book/04-Operators?id=%e7%9f%ad%e8%b7%af) 邏輯運算符支持一種稱為“短路”(short-circuiting)的現象。整個表達式會在運算到可以明確結果時就停止并返回結果,這意味著該邏輯表達式的后半部分不會被執行到。代碼示例: ~~~ // operators / ShortCircuit.java // 邏輯運算符的短路行為 public class ShortCircuit { static boolean test1(int val) { System.out.println("test1(" + val + ")"); System.out.println("result: " + (val < 1)); return val < 1; } static boolean test2(int val) { System.out.println("test2(" + val + ")"); System.out.println("result: " + (val < 2)); return val < 2; } static boolean test3(int val) { System.out.println("test3(" + val + ")"); System.out.println("result: " + (val < 3)); return val < 3; } public static void main(String[] args) { boolean b = test1(0) && test2(2) && test3(2); System.out.println("expression is " + b); } } ~~~ 輸出結果: ~~~ test1(0) result: true test2(2) result: false expression is false ~~~ 每個測試都對參數執行比較并返回`true`或`false`。同時控制臺也會在方法執行時打印他們的執行狀態。 下面的表達式: ~~~ test1(0)&& test2(2)&& test3(2) ~~~ 可能你的預期是程序會執行 3 個**test**方法并返回。我們來分析一下:第一個方法的結果返回`true`,因此表達式會繼續走下去。緊接著,第二個方法的返回結果是`false`。這就代表這整個表達式的結果肯定為`false`,所以就沒有必要再判斷剩下的表達式部分了。 所以,運用“短路”可以節省部分不必要的運算,從而提高程序潛在的性能。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看