title: How to create a generic class that has a generic class as type?
body: <p>In my project I have a Model abstract class, which defined a getId() method and a different classes that extends Model.
  In order to be enable each class to define the type of the ID field as it needs, I made the Model class generic:</p>
  
  <pre><code>public abstract class Model&lt;T&gt; {
      public abstract T getId();
  }
  </code></pre>
  
  <p>So I can extend it now:</p>
  
  <pre><code>public class Person extends Model&lt;String&gt; {
      @Override
      public String getId() {
          return getName();
      }
  }
  </code></pre>
  
  <p>That is ok.</p>
  
  <p>Now I would like to create a class that act as a change set, where I can manage updated and deleted models. In this class, I would like to manage the updated Models using a map, being the model id the key and the model itself the value. (A changeset will have only one type, for instance ChangeSet will only contain person, ChangeSet will only contain cars and so on).</p>
  
  <p>I would like to instantiate it like this:</p>
  
  <pre><code>ChangeSet&lt;Person&gt; changeSet = new ChangeSet&lt;Person&gt;();
  </code></pre>
  
  <p>It makes sense to me that it is possible to infer that the ID will be a String because Person extends Model.</p>
  
  <p>But it doesn't seem to be possible. The nearest I could get were these two alternatives:</p>
  
  <pre><code>public class ChangeSet&lt;M extends Model, T&gt;{
      private final Map&lt;T, M&gt; updated = new HashMap&lt;&gt;();
  ...
  }
  </code></pre>
  
  <p>so I can store in a set the models that were updated. But Eclipse is  compaining that I should specify the generic type of the Model, creating a signature like this:</p>
  
  <pre><code>public class ChangeSet&lt;M extends Model&lt;T&gt;, T&gt;{
      private final Map&lt;T, M&gt; updated = new HashMap&lt;&gt;();
  ...
  }
  </code></pre>
  
  <p>Eclipse is fine with it, but now I need this code to instantiate an object.</p>
  
  <pre><code>ChangeSet&lt;String, Person&gt; changeSet = new ChangeSet&lt;Person&lt;String&gt;, String&gt;();
  </code></pre>
  
  <p>It is not so elegant and having duplicated "String" is awkward.</p>
  
  <p>Is there any way I can get (near) to my desired declaration?</p>