This method must return a result of type boolean(Java)

前端 未结 3 1767
一整个雨季
一整个雨季 2021-01-26 12:14

this is my code.

boolean checkHit2() {
    if (cx < 0 || cx >= 640) {return true;}
    if (cy < ground[(int)cx]) {return false;}
    if (cx < blue +         


        
3条回答
  •  时光取名叫无心
    2021-01-26 12:39

    "This method must return a result of type boolean"

    Means your method should return the boolean value for every case. Currently it will return boolean if one of your if condition is true. What about if none of your if condition is true? In this case compiler will not be able to return anything to the caller of the method. So that compiler is telling you to add a return statement for method for every case no matter condition satisfy or not. You should add return false at the end of the method.

提交回复
热议问题