title: Dependencies between generic classes
body: <p>I have the following Interfaces:</p>
  
  <pre><code>public interface Assembler&lt;T, S&gt; {
     S assemble( T val);
  }
  
  public interface Slicer&lt;T, V&gt; {
     V[] slice(T val);
  }
  </code></pre>
  
  <p>I want to have an Assembler instance use a Slicer instance and call it’s slice(). I have the following:</p>
  
  <pre><code>public class MyAssembler&lt;T, S&gt; implements Assembler&lt;T, S&gt; {
  
     private final Slicer&lt;T, V&gt; slicer;
  
     //ctor
     public MyAssembler() {
       slicer = new MySlicer&lt;T, V&gt;();
     }
  
     @Override
     public S assemble(T val) {         
        V[] v = mySlicer.slice(val);
      }
  </code></pre>
  
  <p>This doesn’t compile because the V type is not known (cannot be resolved to a type) in MyAssembler. I cannot change the Assembler interface to be <code>Assembler&lt;T, S, V&gt;</code>. Is there another way I can define the dependency? This is not an issue with non generic classes. Even if a static factory method is used to get the reference to Slicer, the problem of unknown V would still exist. Any suggestions? If this cannot be done, can anyone recommend a different approach or design pattern that allows for an Assembler to call the Slicer's slice()?</p>