Hi how do I use the constructible feature? Googling it just links me to an extremely sparse haxe documentation. Are there any good examples on the usage?
I’m trying to make a function that only accepts the class definition, not the instance:
class Test {
static function main() {
testFunc(TestClass); // This should work
testFunc(new TestClass()); // This should error
}
@:generic
static function testFunc<T>(cls:T) {}
}
class TestClass {
public function new() {}
}
import haxe.Constraints;
class Test {
static function main() {
testFunc(TestClass); // This should work
testFunc(new TestClass()); // This should error
}
@:generic
static function testFunc<T:Constructible<Void->Void>>(cls:Class<T>):T {
return new T();
}
}
class TestClass {
public function new() {}
}
class Test {
static function main() {
testFunc(TestClass.new);
}
static function testFunc<T>(factory:Void->T):T {
return factory();
}
}
class TestClass {
public function new() {}
}