java - return Statement from each branching -


this question has answer here:

some times found compilation error -

public static boolean returntruefalse(){     if(someconditions) return true;     if(someconditions){       //do       return true;    }     if(someconditions){       //do       return false;    }     //got compilation error here   } 

in above situation got compilation error @ commented portion saying - missing return statement. how can avoid situation?

thanks

well, message of compile error pretty clear : code must encounter return statement of every possible execution path because method has non-void return type. add return statement last case, or throw exception if should not reach state in normal execution.


Comments

Popular posts from this blog

c# - How can I have the VS Debugger break in the correct location for exceptions thrown in Async methods in a Console App? -

php - Issues outputting data after prepared statement with loops -

javascript - How to pass a property by reference -