尽管可以分配Dart参数,但不能分配

问题描述

我目前在理解这一点上有困难。

给出以下内容

class Parent {
  Parent(Function(Parent) initializer);
}

class Child extends Parent {
  //type of initializer can't be parsed to something super() expects.
  Child(Function(Child) initializer) : super(initializer); 
}


void foo(Parent parent) => null;
void bar(Child child) => foo(child);

代码给出错误The argument type 'dynamic Function(Child)' can't be assigned to the parameter type 'dynamic Function(Parent)',但是在foobar中,没有出现预期的错误。有什么区别?

对此我感到非常困惑,因为Child扩展了父级,因此,在面向对象的意义上,孩子是“父级”,因此它应该起作用。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)