相关疑难解决方法(0)

如何从Dart / Flutter中的泛型函数调用命名构造函数

我希望能够从通用函数内部构造一个对象。我尝试了以下方法:

abstract class Interface
{
  Interface.func(int x);
}
class Test implements Interface
{
  Test.func(int x){}
}
T make<T extends Interface>(int x)
{
  // the next line doesn't work
  return T.func(x);
}
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用。而且我收到以下错误消息:The method 'func' isn't defined for the class 'Type'

注意:我不能使用镜子,因为我正在使用带有飞镖的飞镖。

generics constructor dart flutter

6
推荐指数
3
解决办法
882
查看次数

标签 统计

constructor ×1

dart ×1

flutter ×1

generics ×1