title: Dart class inheritance in map function type
body: <pre class="lang-dart prettyprint-override"><code>class A {}
  class B extends A {}
  
  void fA(A a) {}
  void fB(B b) {}
  
  final Map&lt;String, void Function(A)&gt; m = {'test': fB};
  </code></pre>
  
  <p>In the above example, assigning <code>fA</code> to <code>'test'</code> works, but <code>fB</code> generates the error:</p>
  
  <blockquote>
    <p>The element type <code>'(B) → void'</code> can't be assigned to the map value type <code>'(A) → void'</code>.</p>
  </blockquote>
  
  <p>Is there any way of specifying that the value type is a function that takes a parameter that is or extends <code>A</code>?</p>
  
  <p>I also tried <code>void Function&lt;T extends A&gt;(T)</code>, but that generates another error:</p>
  
  <blockquote>
    <p>A generic function cannot be a type argument.</p>
  </blockquote>
  
  <p>The only way that I found to get the project to compile is to cast the value when assigning it, which seems to defy the purpose of type checking, as the value type might as well be <code>dynamic</code> in this case:</p>
  
  <pre class="lang-dart prettyprint-override"><code>final Map&lt;String, void Function(A)&gt; m = {
    'test': fB as void Function(A),
  };
  </code></pre>