How Scala
compiled class would look like if we decompile it?
class Foo {
private var bar = 0
private[this] var bazz = 0
}
object Foo {
def main(args: Array[String]) {
val foo = new Foo
val bar = foo.bar
println(bar)
}
}
It could be
public class Foo {
private int Foo$$bar = 0;
private int bazz = 0;
public static void main(String[] args) {
Foo$.MODULE$.main(args);
}
// getter
public int Foo$$bar() {
return this.Foo$$bar;
}
// setter
private void Foo$$bar_$eq(int x$1) {
this.Foo$$bar = x$1;
}
}
Plus singleton
import scala.Predef;
import scala.runtime.BoxesRunTime;
public final class Foo$ {
public static final Foo$ MODULE$;
static {
MODULE$ = new Foo$();
}
public void main(String[] args) {
Foo foo = new Foo();
int bar = foo.Foo$$bar();
Predef.println((Object) BoxesRunTime.boxToInteger((int) bar));
}
private Foo$() {
//
}
}