如何获取Haxe中的泛型类型?

时间:2019-11-13 06:33:24

标签: 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) {
        var type = Type.typeof(T);

        if (!list.exists(type)) {
            list[type] = [];
        }
        list[type].push(value);
    }
}

这里的问题是当我使用var type = Type.typeof(T);时,编译器对"Unresolved identifier"T

有没有办法做到这一点?

0 个答案:

没有答案