Generics 如何获得Haxe中的泛型类型?

Generics 如何获得Haxe中的泛型类型?,generics,haxe,Generics,Haxe,我想在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) {

我想在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);
    }
}

@:通用
类MyClass{
静态变量列表(null,null):Map=newmap();
公共静态函数myFunction(值:Int){
变量类型=类型。类型(T);
如果(!list.exists(type)){
列表[类型]=[];
}
列表[类型]。推送(值);
}
}
这里的问题是当我使用
var type=type.typeof(T)编译器对
T
“未解析标识符”


有办法做到这一点吗?

我认为这个片段在概念上没有多大意义,这远远不是这里唯一的问题。类级别的类型参数在静态字段中不可用,
@:generic
类甚至不能以静态字段开头(在尝试实例化类时,您将遇到下一个静态字段)。除此之外,
ValueType
不是有效的
Map
键。@Gama11我理解您在脚本中发现的问题(谢谢),但它没有回答问题。我需要知道的是如何在静态函数中获得泛型的类型code
var type=type.typeof(T)不起作用。嗯,这就是我想说的。。。您不能,因为类型参数对静态字段不可用。@Gama11谢谢您的解释,非常有用。