title: Use generic type of one object as type information for another in Java
body: <p>I have a class of type</p>
  
  <pre><code>IDType&lt;IDDataType&gt;
  </code></pre>
  
  <p>and another class of type</p>
  
  <pre><code>SelectionManager&lt;IDDataType&gt;
  </code></pre>
  
  <p>Is there a way that I can infer the data type for objects of the second class by passing an instance of the first one? Something like that</p>
  
  <pre><code>IDType&lt;String&gt; idType = new IDType&lt;String&gt;();
  SelectionManager&lt;idType.getGenericType()&gt; selectionManager = new Se.....
  </code></pre>
  
  <p>Of course, the reason I want to do this is that idType (String is an example here) is created in totally unrelated places.</p>