I have a scala syntax question – say I have a simple dependency pattern construct like the following
trait Master {
val foobar
object SubObject extends SubObject {
foobar = foobar
}
}
trait SubObject {
val foobar
}
Obviously, this will not compile, since the reference
foobar = foobar
is ambiguous.
How do I specify that the RHS of the expression should reference Master’s foobar variable? Is there some sort of special usage of ‘this’ or ‘self’ that I should know about?
I believe the easiest way is to use a self-type definition. In addition to a bunch of cool type-theoretic effects, you can use a self-type to create an alias for “this”. (Haven’t tested this)