I wrote a helper method for a class I am doing in java with Eclipse IDE. The code for that method is as follows
private foo getfooMonitor(String id)
{
if(fooList.isEmpty())
{
if (Mgr.getValue(Name, ListPath + id) == null)
{
return null;
}
}
else
{
for(foo f : fooList)
{
if(f.getID().equalsIgnoreCase(id))
{
return foo;
}
}
return null;
}
}
I am curious as to why if the method will be forced to return something, since it has an if then else
block which has a return
statement hit no matter what, why eclipse would think I do not have a return statement?
Is this eclipse enforcing some weird syntax because it has trouble parsing the if then else
block to see the method will be forced to return, or is this a java thing with not allowing a non void
method to be valid unless it has a return statement as the last line in a method body?
Not all paths return. If
Mgr.getValue(Name, ListPath + id) == null
returns false then your method doesn't have a return value