I have the following method:
public int getValue()
{
if (currentState == COUNTING)
{
for (int i = 0; i < 99; i++)
{
value = i;
return value;
}
}
else
return super.getValue();
}
I am getting the following error: Missing return statement.
the purpose of the method is if the state is the counting state, the value should increment from 0 to 99, and return the value after each incrementation. If the state is not the counting state, it should use the getValue method from the superclass.
You get the error as there is one case that “theoretically” you may not return anything:
Now, it is clear to me (and you) that you will not get there, but not to the compiler.
Apart from this, the return inside the loop makes no sense, as you are going to enter it once, when
iis zero, and return it, but that’s another story which I can’t help with because it’s not clear to me what’s the purpose of this function.