[英]Haxe @:generic causes compiler errors?
Below I have a really boiled down program that has a generic class, then makes an instance of it.下面我有一个非常精简的程序,它有一个通用的 class,然后创建一个实例。 As the code is written, I get a compile time error "MyGeneric> should be MyGeneric_Int".
在编写代码时,我得到一个编译时错误“MyGeneric> 应该是 MyGeneric_Int”。 When I remove the @:generic attributes, it compiles and works fine.
当我删除 @:generic 属性时,它可以编译并正常工作。 Am I misunderstanding the use of @:generic?
我是否误解了@:generic 的使用? Is it even needed here?
这里甚至需要吗? This is on haxe 4.0.5
这是在 haxe 4.0.5 上
@:generic
class MyGeneric<T>
{
public function new (fn:T)
{
trace(fn);
}
}
class Repro
{
static function main()
{
var tracer = getTracer();
}
public static function getTracer():MyGeneric<Any>
{
var arg:Any = 3;
return getGeneric(arg);
}
@:generic
public static function getGeneric<T>(T):MyGeneric<T>
{
return new MyGeneric(T);
}
}
You can do this: return cast getGeneric(arg);
你可以这样做:
return cast getGeneric(arg);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.