title: Android caching instances
body: <p>In performance critical <code>onDraw()</code> method of a <code>View</code>, would it be better to store the instance in a variable and reuse it later or should i just refer my instance as <code>this</code>?</p>
  
  <p>EX:</p>
  
  <pre><code>public class ScheduleListView extends ListView {
  
      private Paint paint = new Paint();
  
      public ScheduleListView(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      @Override
      protected void onDraw(Canvas canvas) {
          paint.setColor(Color.GRAY);
          paint.setAlpha(100);
          paint.setColor(Color.parseColor("#47B3EA"));
          canvas.drawRect(this.getLeft(), 10, this.getRight(), 10, paint);
          super.onDraw(canvas);
          canvas.restore();
      }
  
  }
  </code></pre>
  
  <p>the <code>this</code> is referred in <code>this.getRight()</code> and <code>this.getLeft()</code>, would i have any performance improvement if I do the following modification:</p>
  
  <pre><code>private ScheduleListView scheduleListView  = this;
  
  ... ...
  
  @Override
  protected void onDraw(Canvas canvas) {
      ....
      //refer to my instance using scheduleListView instead of this
      scheduleListView.getLeft() 
      ....
  }
  </code></pre>
  
  <p>is this good practice? Will this have any performance gain? if not, what is a better way of doing this?</p>
  
  <p><strong>PS: I'm asking this because in jQuery(javascript), if I were to use an object multiple times, I would cache the object in a variable</strong>, don't really know would this be helpful in Java or not....</p>
  
  <p>EX:</p>
  
  <pre><code>var myDiv = $(".myDiv");
  myDiv.html();//do stuff
  </code></pre>