如何解决尽管可以分配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)'
,但是在foo
和bar
中,没有出现预期的错误。有什么区别?
对此我感到非常困惑,因为Child扩展了父级,因此,在面向对象的意义上,孩子是“父级”,因此它应该起作用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。