Std. instance

function instance<T:{},S:T>( value : T, c : Class<S> ) : S;

// example class A {} class B extends A {} class C {} ... var a : A = new B(); Std.instance(a,B); // ok Std.instance(a,C); // error