Is it possible to call a generic method forcing the type parameter not by the arguments or return?

31 views
Skip to first unread message

Hitmark7

unread,
Feb 12, 2016, 7:44:51 AM2/12/16
to Haxe
Hello, everybody.

Quick question.

Example with non-compiling code, similar to the one at http://haxe.org/manual/type-system-generic-type-parameter-construction.html :

typedef Constructible = {
public function new():Void;
}

class Test {

public function doIt():Void {
doIt_byType<Array<String>>();
}

@:generic
private function doIt_byType<T:Constructible>():Void {
var foo:T = new T();
trace(foo);
}

}


I'm trying to call doIt_byType forcing the type parameter, because the method doesn't have any parameter and returns Void. Is there any way of doing it? I mean, without the workarounds, like passing a fake argument or returning something with the required type.

Thanks!
Reply all
Reply to author
Forward
0 new messages