I have a Scala object that I need to use in a Java class.
Here\'s the Scala object
object Person {
val MALE = \"m\"
val FEMALE = \"f\"
}
Use Person$.MODULE$
. See also
Edit: A working example (I checked, it compiles and works): Scala:
object Person {
val MALE = "m";
}
Java counterpart:
public class Test {
Person$ myvar = Person$.MODULE$;
public static void main(String argv[]) {
System.out.println(new Test().myvar.MALE());
}
}
In case you use a package object
, the access is a bit different
Scala:
package my.scala.package
package object Person {
val MALE = "m";
}
Java counterpart:
public static void main() {
System.out.println(my.scala.package.Person.package$.MODULE$.MALE);
}