What is the difference between self-types and trait subclasses?

A self-type for a trait A:

trait B
trait A { this: B => }

says that A cannot be mixed into a concrete class that does not also extend B.

On the other hand, the following:

trait B
trait A extends B

says that “any (concrete or abstract) class mixing in A will also be mixing in B”.

Don’t these two statements mean the same thing? The self-type seems to serve only to create the possibility of a simple compile-time error.

What am I missing?

11 Answers
11

Leave a Comment