title: How to check that object is instance of generic in Haxe
body: <p>I'm looking for a safe way to fork logic depending on the object type. I haven't found out how to check if an object belongs to a specific generic type.</p>
  
  <pre><code>class Test {
      static function main() {
          var aa = new AA&lt;Int&gt;();
          //ERROR: Cast type parameters must be Dynamic
          //var a:A&lt;Int&gt; = cast(aa, A&lt;Int&gt;); 
  
          //ERROR: Unexpected )
          //var a:A&lt;Int&gt; = Std.instance(aa, A&lt;Int&gt;);
  
          //OK, but throw run-time exception with flash target. 
          var a:A&lt;Int&gt; = cast aa; 
          a.printName();
  
          //Run-time exception
          a = cast "String is obviously wrong type";
      }
  }
  
  class A&lt;T&gt; {
      public function new () { }
      public function printName() {
          trace("Generic name: A");
      }
  }
  
  class AA&lt;T&gt; extends A&lt;T&gt; {
      public function new () { super(); }
      override public function printName() {
          trace("Generic name AA");
      }
  }
  </code></pre>
  
  <p>Is there a legal way to check if an object belongs to a generic type?</p>