gpt4 book ai didi

dart - mixin 的父类(super class)不是 Object

转载 作者:行者123 更新时间:2023-12-01 22:23:45 25 4
gpt4 key购买 nike

我非常想做下面这样的事情

abstract class A{}                      
abstract class B extends A{}
abstract class C extends A{}
abstract class D extends B with C{} //C cannot be used as a mixin because it extends a class other than object

除了将C的内容复制到D中还有其他解决办法吗?

我类(class)的真实姓名,让您了解我正在尝试做什么

//A Observable
//B DynamicObservable
//C ObservableWithValidationErrors
//D DynamicObservableWithValidationErrors

最佳答案

可用作 mixin 的类有一些限制(请参阅 Mixins in Dart - Syntax and semantics )。

However, in this proposal, a mixin may only be extracted from a class that obeys the following restrictions:

  1. The class has no declared constructors.
  2. The class’ superclass is Object.
  3. The class contains no super calls.

这些限制将来可能会被取消。

The semantics are deliberately restricted in several ways, so as to reduce disruption to our existing implementations, while allowing future evolution toward a full-fledged mixin implementation. This restricted version already provides considerable value.

关于dart - mixin 的父类(super class)不是 Object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27948486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com