This is what my method looks like
public int abc()
{
int x;
if(x > 100)
{
//Say ok
return x;//Causes compiler error
}
//if something more, x = some number
return x;//Causes compiler error
}
I saw an answer at SO – Java: "Local variable may not have been initialized" not intelligent enough?
But, I am still not sure why this error happens. Its a compiler error and not a warning. So, the problem must be something more serious than “taking a safe route”.
Local variables must be initialized before they are accessed. This is why there is a compiler error.
You should must have an error at the
ifstatement where it’s first accessed.