title: Consumer<T> mapped Class<T> in HashMap
body: <p>I want to create an <code>IdentityHashMap&lt;Class&lt;T&gt;, Consumer&lt;T&gt;&gt;</code>. Basically, I want to map a type with a method saying what to do with this type.</p>
  
  <p>I want to dynamically be able to say with objects X, execute Y. I can do </p>
  
  <pre><code>private IdentityHashMap&lt;Class&lt;?&gt;, Consumer&lt;?&gt;&gt; interceptor = new IdentityHashMap&lt;&gt;();
  </code></pre>
  
  <p>but it sucks because then I have to cast the object in the lamba when using it. </p>
  
  <p>Example:</p>
  
  <pre><code>interceptor.put(Train.class, train -&gt; {
      System.out.println(((Train)train).getSpeed());
  });
  </code></pre>
  
  <p>What I would like to do is</p>
  
  <pre><code>private &lt;T&gt; IdentityHashMap&lt;Class&lt;T&gt;, Consumer&lt;T&gt;&gt; interceptor = new IdentityHashMap&lt;&gt;();
  </code></pre>
  
  <p>But it doesn't seem to be allowed. Is there a way to do this ? What is the best workaround to map types with a method for this type ?</p>