Generics 如何将泛型类传递给参数
我必须将数组作为类类型传递。但是,这在以下情况下失败: 意料之外 我怎样才能让它工作呢?试试这个Generics 如何将泛型类传递给参数,generics,parameters,haxe,Generics,Parameters,Haxe,我必须将数组作为类类型传递。但是,这在以下情况下失败: 意料之外 我怎样才能让它工作呢?试试这个 function test(cls:Class<Dynamic>) {} test(Array<Float>); // Unexpected ) 这是不可能的,就像调用函数时不能显式指定函数的类型参数一样。您只需传递数组即可: 编译的一种方法是使用typedef: @:generic private function test<T>(type:Class<
function test(cls:Class<Dynamic>) {}
test(Array<Float>); // Unexpected )
这是不可能的,就像调用函数时不能显式指定函数的类型参数一样。您只需传递数组即可: 编译的一种方法是使用typedef:
@:generic
private function test<T>(type:Class<T>) {
}
test(Array);
typedef FloatArray = Array<Float>;
test(FloatArray);
typedef FloatArray = Array<Float>;
typedef IntArray = Array<Int>;
trace(FloatArray == IntArray); // true