1

Possible Duplicate:
Scala this aliasing and self type

I come across this piece of code.

abstract class Tagged(private var t: Int) { self =>
...
}

I know that the following means a dependency relationship of Tagged and B, but could not understand the above one, could anyone explain the difference ? Thanks

abstract class Tagged(private var t: Int) { self:B  =>
...
}
Community
  • 1
  • 1
zjffdu
  • 25,496
  • 45
  • 109
  • 159

1 Answers1

4

The first form introduces an alias for this; the second form constrains the self-type.

For example, in scala.Enumeration, thisenum is used as an alias for Enumeration.this from nested classes. In the change log appendix to the spec, it says the alias is designed as replacement syntax.

som-snytt
  • 39,429
  • 2
  • 47
  • 129
  • 4
    I would also like to add that aliasing `this` is helpful when you have nested classes and you want to access the `this` of the outer-class from the inner-class. – adelbertc Dec 26 '12 at 08:39
  • Yes, that would be the case with Enumeration, hence an example. – som-snytt Dec 26 '12 at 08:42