我想在Haxe中将泛型与静态方法一起使用,并获取静态方法内部的类型。
我想要类似下面的代码:
@:generic
class MyClass<T> {
static var list(null, null):Map<ValueType, Array<Int>> = new Map<ValueType, Array<Int>>();
public static function myFunction(value:Int) {
var type = Type.typeof(T);
if (!list.exists(type)) {
list[type] = [];
}
list[type].push(value);
}
}
这里的问题是当我使用var type = Type.typeof(T);
时,编译器对"Unresolved identifier"
说T
。
有没有办法做到这一点?