"This method must return a result of type int
Possible problem: the if-statement structure may theoretically
allow a run to reach the end of the method without calling return.
Consider using a final else {... to ensure that return is always called."
My question is... why? My code must return an int as far as I can tell.
private int getNumber(String str, int index) {
String estr=""+str.charAt(index);
if(!Character.isDigit(str.charAt(index)))
return -1;
else {
index++;
while(index<str.length()&&Character.isDigit(str.charAt(index))) {
estr+=str.charAt(index);
index++;
}
return Integer.parseInt(estr);
}
}
The following variation results in the same problem:
private int getNumber(String str, int index) {
String estr=""+str.charAt(index);
if(!Character.isDigit(str.charAt(index)))
return -1;
else {
index++;
while(index<str.length()&&Character.isDigit(str.charAt(index))) {
estr+=str.charAt(index);
index++;
}
return -50;
}
return -100;
}