“Missing return statement” within if / for / while

后端 未结 7 1143
粉色の甜心
粉色の甜心 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:02

    This will return the string only if the condition is true.

    public String myMethod()
    {
        if(condition)
        {
           return x;
        }
        else
           return "";
    }
    

提交回复
热议问题