title: Can I pass a complex type structure in Java generics?
body: <p>I am currently trying to implement an API for a conceptual model using Java interfaces and generics. The model (Transmodel V5.0) is described as an entity-relationship model in great detail, but it does not specify some of the base types used. For example the types of identifiers for the various entities or the types used to establish ordering in sequences are not defined.</p>
  
  <p>Since I want to keep the API as generic as possible I started using generics to configure those details. I do not want to make any assumptions about the types, including not assuming that anything is consistent. Each entity can have a different identifier type, each sequence can have a different type used for ordering purposes.</p>
  
  <p>The problem I am facing is that the complexity grows fast once one entity references another -- not only do I need to pass the types for its identifier, but also everything needed to configure the referenced entity.</p>
  
  <p>For example I have:</p>
  
  <pre class="lang-java prettyprint-override"><code>/**
   * @param &lt;ID&gt; The type for the identifier of this entity.
   * @param &lt;ID_JP&gt; The type identifying journey patterns.
   * @param &lt;OP_JP&gt; The ordering used for points in journey patterns.
   * @param &lt;JP&gt; The type of journey pattern referenced by this entity.
   */
  public interface VehicleJourney&lt;
          ID,
          ID_JP, OP_JP extends Comparable&lt;OP_JP&gt;, JP extends JourneyPattern&lt;ID_JP, OP_JP&gt;
      &gt; extends IdentifiableObject&lt;ID&gt;
  {
      JP getJourneyPattern();
  }
  </code></pre>
  
  <p>I can still read that and make sense of it, but it is getting more than a bit verbose. And then entities like the VehicleJourney can be referenced in other entities, which makes the type parameter list explode. This is pretty much the smallest non-trivial example I can think of.</p>
  
  <p>Is there a way to create a single Java entity modelling the whole configuration of the type system? I am thinking of something that would have all the identifier types and ordering types attached and can then be passed around as one, turning the example above into something like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>public interface VehicleJourney&lt;CONF, JP extends JourneyPattern&lt;CONF&gt;&gt; 
         extends IdentifiableObject&lt;???&gt;
  {
      JP getJourneyPattern();
  }
  </code></pre>
  
  <p>In the spot with the question marks the type of the VehicleJourney identifier would have to be extracted from CONF somehow. If that would be feasible, then the complexity should stay at a manageable level.</p>