title: I cant cast in onclicklistener
body: <p>I have 2 simple different classes that one extends another.
  my first class is:</p>
  
  <pre><code>public class MyObject {}
  </code></pre>
  
  <p>without something in it.</p>
  
  <p>and another:</p>
  
  <pre><code>public class People extends MyObject{
  public  String UserId;
  
  
  public void setUserId(String userId) {
      UserId = userId;
  }
  
  public String getUserId() {
      return UserId;
  }
  }
  </code></pre>
  
  <p>I was going to cast myobject to people in my adapter and in onBindViewHolder method,and I could do it well and worked,as below:</p>
  
  <pre><code>   @Override
  public void onBindViewHolder(final RecyclerViewHolder holder, int position) {
  
          final People people = (People) array.get(position);
          //array is:ArrayList&lt;MyObject&gt; array
          ...}
  </code></pre>
  
  <p>but the problem is when I'm going to do this cast in the same class but in onclicklistener like this:</p>
  
  <pre><code>holder.rlsearchitem.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
              People people1= (People) savedPeopleArray.get(i);
              //savedPeopleArray is:ArrayList&lt;MyObject&gt; savedPeopleArray 
              ....      
              }
          });
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>com.example.qa.setGet.MyObject cannot be cast to com.example.qa.setGet.People
  </code></pre>
  
  <p>why do I get this error even though I used this cast before and it worked?!</p>