문제

Given:

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

Is there a way a can trick the type system into disallowing:

new Foo with Bar with NoBar {}
도움이 되었습니까?

해결책

And type erasure saves the day again:

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 {}

This results in the following error:

illegal inheritance; anonymous class $anon inherits different
type instances of trait Dummy: Dummy[Bar] and Dummy[NoBar]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top