Scala Class and Object disassembled

A Scala Class translates into an equivalent Java Class implementing scala.ScalaObject:

In Scala:

class TestScalaClass

if disassembled produces the following equivalent Java code:

public class TestScalaClass extends java.lang.Object implements scala.ScalaObject{
    public TestScalaClass();
}

The Scala Object which is Scala’s in-language support for Singleton Pattern:

object TestScalaObject

compiles into two bytecode files: TestScalaObject.class and TestScalaObject$.class.

TestScalaObject.class disassembles into:

public final class TestScalaObject extends java.lang.Object{
}

whereas TestScalaObject$.class disassembles into:

public final class TestScalaObject$ extends java.lang.Object implements scala.ScalaObject{
    public static final TestScalaObject$ MODULE$;
    public static {};
}

MODULE$ makes Scala to be accessible through Java.

Advertisements