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.
class Test {
    static function main() {
        var aa = new AA<Int>();
        //ERROR: Cast type parameters must be Dynamic
        //var a:A<Int> = cast(aa, A<Int>); 
        //ERROR: Unexpected )
        //var a:A<Int> = Std.instance(aa, A<Int>);
        //OK, but throw run-time exception with flash target. 
        var a:A<Int> = cast aa; 
        a.printName();
        //Run-time exception
        a = cast "String is obviously wrong type";
    }
}
class A<T> {
    public function new () { }
    public function printName() {
        trace("Generic name: A");
    }
}
class AA<T> extends A<T> {
    public function new () { super(); }
    override public function printName() {
        trace("Generic name AA");
    }
}
Is there a legal way to check if an object belongs to a generic type?
 
     
    