title: Calling getters on an object vs. storing it as a local variable (memory footprint, performance)
body: <p>In the following piece of code we make a call <code>listType.getDescription()</code> twice:</p>
  
  <pre><code>for (ListType listType: this.listTypeManager.getSelectableListTypes())
  {
      if (listType.getDescription() != null)
      {
          children.add(new SelectItem( listType.getId() , listType.getDescription()));
      }
  }
  </code></pre>
  
  <p>I would tend to refactor the code to use a single variable:</p>
  
  <pre><code>for (ListType listType: this.listTypeManager.getSelectableListTypes())
  {
      String description = listType.getDescription();
  
      if (description != null)
      {
          children.add(new SelectItem(listType.getId() ,description));
      }
  }
  </code></pre>
  
  <p>My understanding is the JVM is somehow optimized for the original code and especially nesting calls like <code>children.add(new SelectItem(listType.getId(), listType.getDescription()));</code>. </p>
  
  <p>Comparing the two options, which one is the preferred method and why? That is in terms of memory footprint, performance, readability/ease, and others that don't come to my mind right now.</p>
  
  <p>When does the latter code snippet become more advantageous over the former, that is, is there any (approximate) number of <code>listType.getDescription()</code> calls when using a temp local variable becomes more desirable, as <code>listType.getDescription()</code> always requires some stack operations to store the <code>this</code> object?</p>