You can either used it directly:
// assuming they are in the same package:
String mystr = Outer.Inner$.MODULE$.method();
System.out.println(mystr); // test
// if in other package just:
import packageName.Outer;
String mystr = Outer.Inner$.MODULE$.method();
Or do a static import and use it like this (or similar):
import static packageName.Outer.Inner$.MODULE$;
String mystr = MODULE$.method();
Java doesn’t have any direct equivalent to the singleton object, so for every Scala singleton object, the compiler creates a synthetic Java class with the same name plus a dollar sign appended at the end) for that object and a static field named MODULE$ to hold the single instance of the class. So, to ensure there is only one instance of an object, Scala uses a static class holder.
Your disassembled code looks something like this:
public final class Outer
{
public static class Inner$
{
public static final Inner$ MODULE$;
static {
MODULE$ = new Inner$();
}
public String method() {
return "test";
}
}
}
public final class Outer$ {
public static final Outer$ MODULE$;
static {
MODULE$ = new Outer$();
}
private Outer$() {
}
}