title: Map by Class in Dart
body: <p>I am porting some Java-code to Dart and it heavily uses these kinds of maps:</p>
  
  <pre class="lang-java prettyprint-override"><code>Map&lt;Class&lt;? extends SomeClass&gt;, SomeOtherClass&gt; map = new HashMap&lt;&gt;();
  </code></pre>
  
  <p>At the moment this seems to be impossible in dart. I am aware that there is a proposal to introduce first level types: <a href="http://news.dartlang.org/2012/06/proposal-for-first-class-types-in-dart.html" rel="nofollow">http://news.dartlang.org/2012/06/proposal-for-first-class-types-in-dart.html</a> which would introduce</p>
  
  <pre class="lang-dart prettyprint-override"><code>class Type {
      @native String toString();
      String descriptor(){...} // return the simple name of the type
  }
  </code></pre>
  
  <p>So until this proposal gets implemented I have created following class:</p>
  
  <pre class="lang-dart prettyprint-override"><code>class Type {
      final String classname;
      const Type(this.classname);
      String descriptor() =&gt; classname;
  }
  </code></pre>
  
  <p>and the classes where I need it have a simple get-method</p>
  
  <pre class="lang-dart prettyprint-override"><code>abstract Type get type();
  </code></pre>
  
  <p>That way I can use my <code>Type</code> just like I would use the real <code>Type</code> and to switch later I'd just have to delete my workaround.</p>
  
  <p>My question: Is there some dart-way of doing this kind of mapping (which I am not seeing) or is the way I do it a reasonable workaround until the real <code>Type</code> class gets introduced?</p>
  
  <p><strong>Update for Dart 1.0</strong></p>
  
  <p>It can be done this way:</p>
  
  <pre class="lang-dart prettyprint-override"><code>var map = new Map&lt;Type, SomeOtherClass&gt;();
  // either
  map[SomeOtherClass] = new SomeOtherClass();
  // or
  var instance = new SomeOtherClass();
  map[instance.runtimeType] = instance;
  </code></pre>