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"
}
How can I use this Scala object in Java?
I have tried the following so far without success (compile errors):
Person.MALE()
//returns a String which is useless as I want the actual Person object
Use
Person$.MODULE$
. See alsoEdit: A working example (I checked, it compiles and works): Scala:
Java counterpart:
In case you use a
package object
, the access is a bit differentScala:
Java counterpart: