“C 类用 B 扩展 A 类”和“C 类扩展 A 类”之间有什么区别?以及“C类延伸B”当特质 B 延伸特质 A 时
当两个特质被这样定义时,
trait A
trait B extends A
这两者有什么区别。
class C extends B
class D extends A with B
我认为 C 类或 D 类没有必要扩展特征 A,因为特征 B 已经扩展了特征 A。
为什么经常写成“D 类用 B 扩展 A”?
When two traits are defined like this,
trait A
trait B extends A
what is the difference between these two.
class C extends B
class D extends A with B
I do not think it is necessary for class C or D to extends trait A since trait B already extends trait A.
Why is this often written "class D extends A with B" ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个非常好的问题...我会尝试以主观的回应来回答。
我想当层次结构线性化时,扩展
A
mixin 与B
很重要,在这种特殊情况下,没有区别,但如果你 mixinD 与另一个特征
E
重新实现 A 中的一些(但不是全部)函数,这些函数在B
中不适合您在D
中的需求>。因此,在这种情况下,我们保留
D
is aA
的含义It's a pretty good question... I'll try to answer with a subjective response.
I guess that extends
A
mixin withB
is important when the hierarchy will be linearized, in this particular case there is no differences but what if you mixinD
with another traitE
that reimplements some (but not all) functions from A which aren't well advised inB
for your needs inD
. So you'd haveMoreover in that case, we keep the meaning that
D
is aA