title: In Java, is it more expensive to create an object, or get the objects value?
body: <p>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:</p>
  
  <pre><code>if( foo.getOb().getVal() == CONST_0 )
  {
       ....
  }
  ....
  if( foo.getOb().getVal() == _CONST_N )
  {
       ....
  }
  else
       ....
  </code></pre>
  
  <p>OR:</p>
  
  <pre><code>int x = foo.getOb().getVal();
  if( x == CONST_0 )
  {
       ....
  }
  ....
  if( x == _CONST_N )
  {
      ....
  }
  else
      ....
  </code></pre>
  
  <p>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. </p>
  
  <p>Thanks a lot for any answers!</p>