gpt4 book ai didi

scala - 禁止混合特定特征

转载 作者:行者123 更新时间:2023-12-03 18:25:53 25 4
gpt4 key购买 nike

鉴于:

trait Foo
trait Bar { this: Foo => }
trait NoBar { this: Foo => }

有没有办法可以欺骗类型系统禁止:
new Foo with Bar with NoBar {}

最佳答案

并键入删除再次节省一天:

trait Foo
trait Dummy[A]
trait Bar extends Dummy[Bar]{ this: Foo => }
trait NoBar extends Dummy[NoBar]{ this: Foo => }
new Foo with Bar with NoBar {}

这会导致以下错误:
illegal inheritance; anonymous class $anon inherits different
type instances of trait Dummy: Dummy[Bar] and Dummy[NoBar]

关于scala - 禁止混合特定特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14010461/

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