title: Java 8 generic map of functions
body: <p>Not sure if this is even possible; I admit I am not as good at generics as I would like to be. </p>
  
  <p>Basically, I want to create a map of class -> function
  where the class used for the key is the class of the input to the function, like such (not legal syntax): </p>
  
  <pre><code>public static Map&lt;Class&lt;T&gt;,Function&lt;T,Expression&gt;&gt; STUFF = new HashMap&lt;&gt;();
  
  {
      STUFF.put(List.class, ListExpression::new);
      STUFF.put(String.class, StringExpression::new);// this constructor must take string
  }
  </code></pre>
  
  <p>so that if I do:</p>
  
  <pre><code>Function&lt;String,Expression&gt; e = STUFF.get(o.getClass());
  Expression ex = e.apply(o);
  </code></pre>
  
  <p>It gets the types right for me. </p>