“Missing return statement” within if / for / while

后端 未结 7 1059
粉色の甜心
粉色の甜心 2020-11-22 02:02

I have a question regarding return statements used within if() while() or for() statements. As you can see in the following method, it

7条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 02:16

    Any how myMethod() should return a String value .what if your condition is false is myMethod return anything? ans is no so you need to define return null or some string value in false condition

    public String myMethod() {
        boolean c=true;
        if (conditions) {
            return "d";
        }
        return null;//or some other string value
    }
    

提交回复
热议问题