title: Java: What's the right way of writing a generic HashMap merge method?
body: <p>This is probably a basic Java question but I somehow can't find the right keywords to google for the right solution.</p>
  
  <p>I have several pairs of <code>HashMap</code> objects and I need to merge each respective pair in a straightforward ways: if two keys match, add up the two values and store the sum in the first map. So I might have something like:</p>
  
  <pre><code>HashMap&lt;String,Double&gt; mapSD1, mapSD2;
  HashMap&lt;String,Integer&gt; mapSI1, mapSI2;
  HashMap&lt;MyClassA,Float&gt; mapCF1, mapCF2;
  </code></pre>
  
  <p>What is the right way of writing a generic <code>mergeMaps</code> methods that can merge all these types, instead of having 3 more or less identical methods for each type?</p>