I have a Scala/Java dual language project where I need to pass a Scala enumeration from Java.
object MonthSelection extends Enumeration {
type MonthSelection = Value
val LastMonth, ThisMonth, NextMonth, CustomMonth = Value
}
class MyClass {
def doDateStuff(monthChosen: MonthSelection) = {
// do stuff
}
}
How do I call this from Java? I am getting a compile error as I cannot seem to import scala.Enumeration.Value.
MyClass myClass = new MyClass();
myClass.doStuff(MonthSelection.ThisMonth);
When in doubt, look at the generated bytecode. 🙂
Ok, easy. All of these enumerations are public static methods. I just have to import scala.Enumeration and directly invoke these methods.
Hope this gives you more ideas to play with. 🙂