title: Generics confusion
body: <p>Apologies for the <em>generic</em> title, I can't really think of a way to explain this.</p>
  
  <p>I'd like to model a scenario where a system provides <em>facilities</em> to users, which have associated <em>policies</em> applied to <em>requests</em> against those facilities.</p>
  
  <pre><code>public interface Facility {
      public List&lt;Policy&gt; getPolicies();
  }
  public interface Policy {
      public void apply(Facility facility, Request request);
  }
  public interface Request {
  
  }
  </code></pre>
  
  <p>But a request can only be sensible for a particular type of facility, and a policy can really only apply to a type of facility and a type of request specific to that type of facility.</p>
  
  <pre><code>public interface Facility&lt;F extends Facility&lt;F&gt;&gt; {
      public List&lt;Policy&lt;F, ? extends Request&lt;F&gt;&gt;&gt; getPolicies();
  }
  public interface Policy&lt;F extends Facility&lt;F&gt;, R extends Request&lt;F&gt;&gt; {
      public void apply(F facility, R request);
  }
  public interface Request&lt;F extends Facility&lt;F&gt;&gt; {
  
  }
  </code></pre>
  
  <p>But I'd also like to be able to specify policies overall, such that they can apply to any Facility supertype.</p>
  
  <pre><code>public interface Facility&lt;F extends Facility&lt;F&gt;&gt; {
      public List&lt;Policy&lt;? super F, ? extends Request&lt;F&gt;&gt;&gt; getPolicies();
  }
  </code></pre>
  
  <p>But in reality you're only ever going to want to query the policies that apply to a particular type of request for the facility.</p>
  
  <pre><code>public interface Facility&lt;F extends Facility&lt;F&gt;&gt; {
      public &lt;R extends Request&lt;F&gt;&gt; List&lt;Policy&lt;? super F, R&gt;&gt; getPolicies();
  }
  </code></pre>
  
  <p>My problem is now I'm so confused with all the generics and I'm not able to even create a policy class that applies to all Facilities, which would be something like this, if it were legal</p>
  
  <pre><code>public class GeneralPolicy implements Policy&lt;T extends Facility&lt;T&gt;, Request&lt;T&gt;&gt;
  </code></pre>
  
  <p>How do I go about making it possible to associate types of facility, policy and request in such a way that makes sense according to the description above? I'm sure people will ask for clarification, I've battled with this long enough that I'm probably not explaining something, or completely missing an obvious point.</p>