title: Java generics parameters with base of the generic parameter
body: <p>I am wondering if there's an elegant solution for doing this in Java (besides the obvious one - of declaring a different/explicit function. Here is the code:</p>
  
  <pre><code>private static HashMap&lt;String, Integer&gt; nameStringIndexMap 
          = new HashMap&lt;String, Integer&gt;();
  private static HashMap&lt;Buffer, Integer&gt; nameBufferIndexMap 
          = new HashMap&lt;Buffer, Integer&gt;();
  
  // and a function
  private static String newName(Object object, 
          HashMap&lt;Object, Integer&gt; nameIndexMap){
      ....
  }
  </code></pre>
  
  <p>The problem is that I cannot pass <em>nameStringIndexMap</em> or <em>nameBufferIndexMap</em> parameters to the function. I don't have an idea about a more elegant solution beside doing another function which explicitly wants a <em>HashMap&lt;String, Integer&gt;</em> or <em>HashMap&lt;Buffer, Integer&gt;</em> parameter.</p>
  
  <p>My question is:
  Can this be made in a more elegant solution/using generics or something similar?</p>
  
  <p>Thank you,</p>
  
  <p>Iulian</p>