<strike id="5ntnv"><i id="5ntnv"><del id="5ntnv"></del></i></strike>
<strike id="5ntnv"></strike><ruby id="5ntnv"></ruby><del id="5ntnv"><dl id="5ntnv"><del id="5ntnv"></del></dl></del><strike id="5ntnv"><dl id="5ntnv"><del id="5ntnv"></del></dl></strike>
<strike id="5ntnv"></strike>
<strike id="5ntnv"></strike>
<span id="5ntnv"><dl id="5ntnv"></dl></span>
<strike id="5ntnv"><i id="5ntnv"><del id="5ntnv"></del></i></strike><th id="5ntnv"><noframes id="5ntnv"><span id="5ntnv"><dl id="5ntnv"><del id="5ntnv"></del></dl></span>
<span id="5ntnv"></span>
<strike id="5ntnv"><dl id="5ntnv"><del id="5ntnv"></del></dl></strike>
<strike id="5ntnv"><dl id="5ntnv"><del id="5ntnv"></del></dl></strike><strike id="5ntnv"><i id="5ntnv"></i></strike><span id="5ntnv"></span>
<strike id="5ntnv"></strike>
<strike id="5ntnv"></strike>
<th id="5ntnv"><noframes id="5ntnv">
<ruby id="5ntnv"></ruby>
<strike id="5ntnv"><dl id="5ntnv"></dl></strike>

貴州網站建設公司貴州網站建設公司

java unreachable code不可達代碼

例子:

 static int test(int testval) {
    int target = 1;
    if (testval > target)
       System.out.println(1);
    return -1;(下邊是可達永遠不會達到的代碼,所以編譯器提示錯誤(unreachable code))
    if (testval < target)
       return +1;
    return 0; // match
 }、代碼

修改為讓return -1 與上邊的可達if為一體的就行,修改如下:

 static int test(int testval) {
    int target = 1;
    if (testval > target)
           return -1;

    if (testval < target)
       return +1;
    return 0; // match
 }

 或者這樣直接輸出:

 static int test(int testval) {
    int target = 1;
    if (testval > target)
       System.out.println(1);
    if (testval < target)
       return +1;
    return 0; // match
 }

注:始終遵循著if  if  條件判斷原則,代碼上邊那個滿足就不在執行下邊的可達代碼 

 

public boolean check() {   String str = null; for (int i = 0; i < 1; i++) for (int j = 0; j < 1; j++) if (str == null) return true; return false; }

  System.out.println(new Type().check());  true

作者:love_you_girl
來源鏈接:https://www.cnblogs.com/love-you-girl/p/3901631.html

贊(52129)
未經允許不得轉載:>貴州網站建設公司 » java unreachable code不可達代碼
国产欧美精品