Possible duplicate:
What is the difference between scala subclasses and type types?
I understand self annotation as a promise to the compiler, where the programmer shows that the trait will mix with the annotated one. For instance:
scala> trait X
defined trait X
scala> trait Y { this: X => }
defined trait Y
scala> new Y {}
<console>:10: error: illegal inheritance;
self-type Y does not conform to Y selftype Y with X
new Y {}
^
scala> new Y with X {}
res1: Y with X = $anon$1@1125a40
In the previous example, the third expression failed because we did not set the actual X to a new instance. Obviously, the latter works well. So far, so good. And now let's look at another example that includes an object.
scala> object Z { this: X => }
defined module Z
I understand that the object is created with an error with the promise of X (we are creating an instance now with a future promise!), As shown in the following lines, where the properties have been slightly changed:
scala> trait X { class X1 }
defined trait X
scala> trait Y { this: X => new X1 }
defined trait Y
scala> object Z { this: X => new X1 }
<console>:8: error: not found: type X1
object Z { this: X => new X1 }
^
So what does object annotation mean?
jeslg source
share