title: Generics and inheritance - only supertypes needed in code
body: <p>I need to work with a generic class and its type argument in my client code.</p>
  
  <pre><code>public class Usable {
      ...
  }
  
  
  public interface User&lt;T extends Usable&gt; {
      public void use(T usable);
  }
  
  
  //client
  public class UserDemo { 
      public void demo() {
          Usable usable = getUsable();    //returns Usable
          User&lt;? extends Usable&gt; user = getUser();    //returns User&lt;? extends Usable&gt;
  
          user.use(usable); //compilation error.
      }
  
      public Usable getUsable() {
          ....
      }
  
      public User&lt;? extends Usable&gt; getUser() {
          ....
      }
  }
  </code></pre>
  
  <p>The compilation error is that the expected type is <code>&lt;? extends Usable&gt;</code> but the passed type is <code>Usable</code>. How do I get around this problem? The constraints are:</p>
  
  <ol>
  <li>The client code(<code>UserDemo</code>) can only work on <code>User</code> and <code>Usable</code> (not their subtypes). </li>
  <li>User can only work on objects whose types are subtypes of <code>Usable</code>.</li>
  </ol>