cast(myInstance, MyClass);
var lClass:Class<Dynamic> = MyClass;cast(myInstance, lClass);
src/Main.hx:20: characters 27-28 : Unexpected )
private function getChild<T>(childName:String):T { var child:DisplayObject = getChildByName(childName); if (child == null) { throw "Child with name " + childName + " not found"; } if (!Std.is(child, T)) { throw "Child with name " + childName + " is not an instance of " + Type.getClassName(T); } return cast(child, T); }
src/UIComponent.hx:79: characters 22-23 : Type parameter T is only available at compilation and is not a runtime valuesrc/UIComponent.hx:85: characters 27-28 : Type parameter T is only available at compilation and is not a runtime valuesrc/UIComponent.hx:86: characters 97-98 : Type parameter T is only available at compilation and is not a runtime valuesrc/UIComponent.hx:89: characters 15-29 : Can't cast to a type parametersrc/UIComponent.hx:76: lines 76-90 : Missing return getChild.TBuild halted with errors (haxe.exe).
Std.is(child, T)
src/UIComponent.hx:79: characters 22-23 : Type parameter T is only available
> at compilation and is not a runtime value
getChild<Graphics>("_gridZone", Graphics);
getChild("_gridZone", Graphics);
private function getChild<T>(childName:String, type:Class<T>):T {
var child:DisplayObject = getChildByName(childName); if (child == null) { throw "Child with name " + childName + " not found"; }
if (!Std.is(child, type)) { throw "Child with name " + childName + " is not an instance of " + Type.getClassName(type); } return cast child; }
Type.getClassName(type)
untyped type.prototype.constructor.name