title: Java coding style on create new local variable to refer to class member variables
body: <p>This is a general coding style question regarding which style is more general or elegant. </p>
  
  <p>When reading Java collection source code, I found the first style more frequently than the second one. Could anyone shred some light/ reasoning on this?  IMHO, the second style is more concise than the first one, but actually, the first one should be redeemed more elegant in some way I cannot argue. </p>
  
  <ol>
  <li>creating local variable.</li>
  </ol>
  
  <pre class="lang-java prettyprint-override"><code>private Set&lt;K&gt; keySet;
  
  public Set&lt;K&gt; keySet() {
      Set&lt;K&gt; ks = keySet;
      if (ks == null) {
          ks = new KeySet();
          keySet = ks;
      }
      return ks;
  }
  
  </code></pre>
  
  <ol start="2">
  <li>operating on class member variable.</li>
  </ol>
  
  <pre class="lang-java prettyprint-override"><code>public Set&lt;K&gt; keySet() {
      if (keySet == null) {
          keySet = new KeySet();
      }
      return keySet;
  }
  </code></pre>