title: Android View.post() method making excessive reference
body: <p>Sorry I can't come up with a better question title because it's pretty hard to describe...</p>
  
  <p>I was inspecting Android's source (4.4 KK), the <code>View</code> class in particular and this showed up:</p>
  
  <pre><code>// .... lots of stuff....
  AttachInfo mAttachInfo;
  // .... lots of stuff....
  public boolean post(Runnable action) {
      final AttachInfo attachInfo = mAttachInfo;
      if (attachInfo != null) {
          return attachInfo.mHandler.post(action);
      }
      // Assume that post will succeed later
      ViewRootImpl.getRunQueue().post(action);
      return true;
  }
  </code></pre>
  
  <p>That's the <code>View.post(Runnable)</code> that we all love to use whenever we need something to run on the UI thread.</p>
  
  <p>The thing I don't understand here is why do they create another local reference of <code>attachInfo</code>? </p>
  
  <p>Why don't they do it like:</p>
  
  <pre><code>    if (mAttachInfo != null) {
          return mAttachInfo.mHandler.post(action);
      }
  </code></pre>
  
  <p>Other than making <code>attachInfo</code> immutable in the method scope to prevent bugs(even thought they can still accidentally access <code>mAttachInfo</code>), I don't think there's any reason to do this.</p>
  
  <p>Another possibility would be to shorten names, but I don't think it's worth shorting 1 character.</p>
  
  <p>Is this a design pattern?</p>
  
  <p><strong>EDIT:</strong> 
  further inspecting the source reveals that they use this "pattern" in many places:</p>
  
  <pre><code>public void postInvalidateOnAnimation() {
      // We try only with the AttachInfo because there's no point in invalidating
      // if we are not attached to our window
      final AttachInfo attachInfo = mAttachInfo;
      if (attachInfo != null) {
          attachInfo.mViewRootImpl.dispatchInvalidateOnAnimation(this);
      }
  }
  </code></pre>
  
  <p>Basically, they use it in almost every <code>postXXXXXX()</code> method.</p>
  
  <p><strong>EDIT2:</strong></p>
  
  <p>@CommonsWare pointed out that it might be used for anonymous inner class in previous versions, I checked the source of 1.5(Cupcake) ~ 2.3.3(Gingerbread) and this is what <code>post(</code>) looks like</p>
  
  <pre><code>public boolean post(Runnable action) {
      Handler handler;
      if (mAttachInfo != null) {
          handler = mAttachInfo.mHandler;
      } else {
          // Assume that post will succeed later
          ViewRoot.getRunQueue().post(action);
          return true;
      }
  
      return handler.post(action);
  }
  </code></pre>
  
  <p>I still don't see why....</p>