I have a code like this.
public void test()
{
final boolean passDay = true;
final int status;
//if the right side takes place means i need status value below and is set
//if only the left side is takes place i dont care about status because i will not use it
if(!passDay && ((status=loadStatusValue()))== Constants.YORK_CORK_EMPTY_SET)
System.out.println("inside 1");//I DONT CARE ABOUT STATUS VALUE
else
{
if(passDay)System.out.println("BAMBA");//I DONT CARE ABOUT STATUS VALUE
else
{
//HERE STATUS ALWAYS WILL HOLD A VALUE SIMPLYBECAUSE RIGHT SIDE
//IS ALREADY EVALUATED BECAUSE passDay=false and !passDay=true
System.out.println(status);
//I MEAN I USE STATUS ONLY AFTER BEING INITIALIZED
//WHY variable status might not have been initialized IS SHOW IF I AM HERE IS BECAUSE STATUS HAS A VALUE.
}
}
}
private boolean compute(){return true;}
private int loadStatusValue(){return Constants.BOTH_YORK_CORK_SET;}
What i think in this method everything works i use the status int variable when was already set even is not defined in the initialization.
As you can see the passDay is a boolean means only could hold true or false i have try hardcoded with true and false and not compilation error is show when shows a compilation error when instead being hardcode i do something like it.
final boolean passDay = compute();
in fact compute is also returning a boolean could be true or false but in this case a compilation error is show variable status might not have been initialized but can't java realize that even when true status is just not used and when false the status variable is initialized or set it and used later or i am wrong?