개체 유형에 따라 논리를 포크하는 안전한 방법을 찾고 있습니다. 개체가 특정 제네릭 형식에 속하는지 확인하는 방법을 찾지 못했습니다.해당 개체가 Haxe에서 일반 인스턴스인지 확인하는 방법
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");
}
}
개체가 제네릭 형식에 속하는지 여부를 확인할 수있는 합법적 인 방법이 있습니까?
Flash에서 실행중인 런타임 예외를 재현 할 수 없습니다. 또한 코드 스 니펫에 'B'에 대한 유형 선언이 누락 된 것 같습니다. – Gama11
SWF 타겟 및 디버그 플래시 플레이어로 http://try.haxe.org/#C6a93에서 확인할 수 있습니다. – kolonitsky