So say for example I'm going through an 'if' block and in this block, I am comparing the value of some number to a constant. Would it be more expensive like this:
if( foo.getOb().getVal() == CONST_0 )
{
....
}
....
if( foo.getOb().getVal() == _CONST_N )
{
....
}
else
....
OR:
int x = foo.getOb().getVal();
if( x == CONST_0 )
{
....
}
....
if( x == _CONST_N )
{
....
}
else
....
I know that this may seem like a stupid question. I think that the second implementation is fast/more efficient but I'm curious as to why. I've been trying to think of the reason for the last couple of minutes and can't really come up with anything since my knowledge on Java is...a bit lacking.
Thanks a lot for any answers!