You can have type smoothing and this
at the same time:
abstract class Parser[+T] { p: SomeAssumedType => β¦ }
If you did not specify a record type, Scala will assume that the variable type is the type of the surrounding class, giving you a simple alias for this
.
If you save the name this
with agitation, then Scala expects you to initialize this class so that the label can execute.
How to smooth this
. Here is the situation in which this is necessary:
object OuterObject { outer => val member = "outer" object InnerObject { val member = "inner" val ref1 = member val ref2 = this.member val ref3 = outer.member def method1 = { val member = "method" member } def method2 = { val member = "method" this.member } def method3 = { val member = "method" outer.member } } } scala> OuterObject.InnerObject.ref1 res1: java.lang.String = inner scala> OuterObject.InnerObject.ref2 res2: java.lang.String = inner scala> OuterObject.InnerObject.ref3 res3: java.lang.String = outer scala> OuterObject.InnerObject.method1 res4: java.lang.String = method scala> OuterObject.InnerObject.method2 res5: java.lang.String = inner scala> OuterObject.InnerObject.method3 res6: java.lang.String = outer
source share