posted 14 years ago
Often times I come across code as such...
boolean isValid = someObject.isValid();
if (isValid) { // isValid only being used in one place
....
}
other than the fact that the variable is declared outside of the block in which it is being used, is there a performance hit (no matter how small) to doing this or does the compiler figure it out and optimize the call
This question does not apply to those cases where readability is to be take into account such as...
double commissionAmount = someObject.someReallyScrewyMethodName();
if(commissionAmount > 15.43) { // used once - var for readability only
...
}
Thanks, in advance
Thomas Bigbee - SCJP, SCJD, SCWCD