I am learning Scala and I was trying to figure out how 'self type' works for trait.
Especially trying out to reassign the 'this' field.
I was able to reassign 'this' once but I didn't understand how it works behind the scene. I tried to see if we can reassign this twice but it failed with a weird error.
trait DepositAccount {
this : Account =>
def print(): Unit = {
println(s"Balance: $getBalance")
}
this: Profile =>
def printName(): Unit = {
println(s"Name: $getName")
}
}
Following is the error.
';' expected but '=>' found.
this: Profile =>