title: Declaring subtype captures in an interface method
body: <p>I am basically trying to achieve the following syntax (currently, doesn't compile). If someone can explain how to achieve this, I would appreciate it. Complicating matters is I have the 'add' method overloaded repeatedly</p>
  
  <pre><code>public interface Organization {
      Organization add(Hub hub);
  }
  
  public class JpaOrganization implements Organization {
  
  
      @OneToMany(mappedBy = "organization", cascade = CascadeType.ALL)
      private Set&lt;JpaHub&gt; hubs = new LinkedHashSet&lt;&gt;();
  
  
      @Override
      public JpaOrganization add(JpaHub hub) {
          hub.setOrganization(this);
          hubs.add(hub);
          return this;
      }
  }
  
    public interface Hub {
      void setOrganization(Organization organization);
    }
  
  
  public class JpaHub implements Hub {
      @Override
      public void setOrganization(JpaOrganization organization) {
          this.organization = organization;
      }
  }
  </code></pre>
  
  <p>I am trying to do this to abstract a DAO layer away for an expected migration. So, all "JPA" implementations can assume they are dealing with JPA implementations, which is essential for all the reflection to work.</p>
  
  <p>I need to capture the types but the syntax for this particular arrangement evades me. </p>
  
  <p>I have tried something like:</p>
  
  <pre><code>&lt;O extends Organization, H extends Hub&gt; O foo(H hub);
  </code></pre>
  
  <p>implementation:</p>
  
  <pre><code>   @Override
      public JpaOrganization add(Hub hub) {
          return this;
      }
  </code></pre>
  
  <p>And this compiles but gives me a checked warning which indicates to me I might be doing something wrong. Based on what I am reading I am not sure I can do this without some warnings.</p>