In this one, the retVal = null accomplishes nothing. You give it a value of null. You never have code that uses that value. Then you give it another value, depending on whether you do the if-then or the else part.
In code that falls where I've added the comment, you can use or change the value of retVal.
void A(String pizza) {
String retVal = null;
... code in here could use it or give it a new value ...
if(StringUtils.isBlank(pizza) {
retVal = "blank"
} else {
retVal = computeString(pizza);
}
... additional code here might change it (and can use it's value) ...
}
In this one, you are required to give retVal a value everytime the method is called. Your if-then-else code does that. The value can never be changed after it is given a value.
One difference is that the compiler would tell you if you used retVal before giving it a value. It would, reasonably, tell you that the variable has no value yet.
void A(String pizza) {
final String retVal;
... code in here cannot use it or give it a value, too ...
if(StringUtils.isBlank(pizza) {
retVal = "blank"
} else {
retVal = computeString(pizza);
}
... additional code here cannot change it but can use it's value ...
}
finalon the first A?