Closed
Description
In Scala 2, private variables in a class would be defined in the class. In Scala 3 they seem to be defined in the constructor.
I ran into this because I had weak references to the variables and then the variables got garbage collected - which was not what I wanted.
Compiler version
3.1.0-RC3
Minimized code
class Foo(i: Int) {
private val bar: Int = 0
}
seems to give the equivalent in Java of...
public class Foo
{
Foo(int i) {
int bar = 0;
}
}
when in Scala 2 it gave...
public class Foo
{
private int bar = 0;
Foo(int i) {
}
}
I think Scala 2 also defined private[this] val
in the class, not the constructor.