7

鉴于:

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

有没有办法可以欺骗类型系统来禁止:

new Foo with Bar with NoBar {}
4

1 回答 1

12

类型擦除再次节省了时间:

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]
于 2012-12-23T11:48:14.753 回答