In Java, we can extend the current scope in a method to refer variables with this if it is hidden by a formal parameter. A typical example is what we do in constructors:
class A {
int i;
A(int i) { this.i = i; }
}
Now, is there any similar trick in Scala? For instance, I have a definition like this:
class A(i: Int) {
val i = i; // ?
}
A trivial solution would be to rename one of the parameters to something else (like using underscores in C++), but I would like to avoid that.
Is there any alternatives for this?
Thanks in advance!
Is it exactly the same? Then just declare it a
val(orvar):Is it not exactly the same? Then you’ll have to use two names.