Why a self-type class can declare a class

I know that Scala can only use mixin properties, it makes sense to inject dependencies and a cake template. My question is why I can still declare a class that needs a different β€œclass”, but not an exponent.

The code:

class C class D { self : C =>} 

This is still done. I thought this was not compiled, because at this stage, like a new instance of D (C is not a sign of the class).

Edit:

when trying to create an instance of D:

new D with compilation error C // class C should be a sign that should be mixed.

+7
scala
source share
1 answer

You must explicitly make class D before extends C as follows:

 class C class D extends C { self: C => } 

In addition, you can refer to the message Is the class self-name of another class? that clearly explains this problem.

0
source share

All Articles