I am trying to instantiate a class based on a function type parameter.
Although the documentation says it is possible, I cannot get it to work.
Consider the following code:
class Dialog
{
public function new()
{
}
}
class TestDialog extends Dialog
{
public function new()
{
super();
}
}
class SomeAppClass
{
public function new()
{
var instance = create(TestDialog);
}
@:generic
function create<T:Dialog>(type:Class<T>):T
{
return new T();
}
}
This does not work with the following error:
create.T does not have a constructor
It’s clear that I am doing something wrong, but what?
source
share