gpt4 book ai didi

syntax - dart mixin 'with' 不能在没有 'extends' 的情况下使用?

转载 作者:行者123 更新时间:2023-12-04 05:39:46 25 4
gpt4 key购买 nike

我在 Webstorm 6.0.2 中工作,在尝试使用 mixin 语法时出现错误:

class A{}

class B with A{} //error can't use with syntax without an extends?

为什么我不能使用 with没有 extends ?当然每个类都隐含 extends Object .

最佳答案

这是a really clear explanation from Ladislav Thon :

[...] there's a simple advice, which is actually semantically correct: in the declaration class C extends SC with M1, M2, M3 implements I1, I2 { ... }, imagine parenthesis around the content of the extends clause. They will look like this: class C extends (SC with M1, M2, M3) implements I1, I2 { ... }. Which means that class C doesn't extend SC, it extends SC_with_M1_with_M2_with_M3.

Or, put another way: the class declaration has an extends clause and an implements clause, but it doesn't have a with clause. Instead, the with clause belongs inside the extends clause.


another point from Florian Loitsch :

When you extend "Object" with a mixin the first mixin can always take the place of "Object".


所以你的 class B with A应该是 class B extends Object with A这也相当于 class B extends A .

关于syntax - dart mixin 'with' 不能在没有 'extends' 的情况下使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17208850/

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