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

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -