title: How to Correctly return something that extends from a class and implements an interface?
body: <h2>Background</h2>
  
  <p>This question is for both Java and Android developers.</p>
  
  <p>On Android, I want to have a function that returns something that extends from <a href="http://developer.android.com/reference/android/view/View.html" rel="noreferrer"><strong>View</strong></a> and implements <a href="http://developer.android.com/reference/android/widget/Checkable.html" rel="noreferrer"><strong>Checkable</strong></a>, both are part of the Android API.</p>
  
  <h2>What I've tried</h2>
  
  <p>After searching a bit here and on other places on the Internet, I've found this solution:</p>
  
  <pre><code>private &lt;T extends View &amp; Checkable&gt; T get() {
      return (T) mView;
  }
  </code></pre>
  
  <p>Note that mView is of any type that extends View (and there are plenty) but I guarantee that it implements Checkable since only those types get to be there.</p>
  
  <p>This shows a warning of "Type safety: Unchecked cast from View to T" , but that's not the problem.
  The problem is that I can't use this method correctly, for example:</p>
  
  <pre><code>View v=get(); //this works fine
  Checkable c=get(); // this shows error
  </code></pre>
  
  <p>the second line shows the error:</p>
  
  <blockquote>
    <p>Bound mismatch: The generic method get() of type ... is not
    applicable for the arguments (). The inferred type Checkable&amp;View is
    not a valid substitute for the bounded parameter </p>
  </blockquote>
  
  <p>So I've tried using "," instead of "&amp;" . same error.</p>
  
  <p>However, when I use "," and reverse the order , I get a warning "The type parameter View is hiding the type View" , and both lines work fine. </p>
  
  <p>This is the code:</p>
  
  <pre><code>private &lt;T extends Checkable, View&gt; T get() {
      return null;
  }
  
  private void foo() {
      final View v = get(); // this works fine
      final Checkable c = get();// this works fine too
  }
  </code></pre>
  
  <p>However, when I send the returned type to other functions, they don't get the type itself as something that extends the class and the interface, and need casting all the time (to View).</p>
  
  <h2>The question</h2>
  
  <p>What is the correct way to do it?</p>
  
  <p>If the last way I've shown is the correct one, why do I get a warning about it? and why is the order important if there is always a max of one class to extend ?</p>