Scala多个

vir*_*yes 11 scala traits

Scala新手.语言非常简洁.

好奇为什么实现多个特征需要多个"with"语句.

例如:

class Foo extends Bar with A with B with C {}
Run Code Online (Sandbox Code Playgroud)

class Foo extends Bar with A, B, C {}
Run Code Online (Sandbox Code Playgroud)

Deb*_*ski 27

考虑一下

class Foo[A, B]

new Foo[Bar with D with E, Bar with E] {}
Run Code Online (Sandbox Code Playgroud)

VS

new Foo[Bar with D, E, Bar with E] {}
Run Code Online (Sandbox Code Playgroud)

它并非在所有情况下都不明确.