The solution I am going to test is to use a DummyImplicit
, so I can have the same method name for both the Scala and the Java method:
class ScalaService {
// To be called from Scala
def process(s: Option[String], i: Option[Int])(implicit d: DummyImplicit) {
println("1: " + s + ", " + i)
}
// To be called from Java
def process(s: Option[String], i: Option[java.lang.Integer]) {
print("2: ")
process(s, i.map(v => v.toInt))
}
to be used from Scala like this:
object ScalaService extends App {
val s = new ScalaService()
s.process(Some("Hello"), Some(123))
}
and from Java:
public class Java {
public static void main(String[] args) {
ScalaService service = new ScalaService();
{
scala.Option<String> so = scala.Option.apply("Hello");
scala.Option<Integer> io = scala.Option.apply(10);
service.process(so, io);
}
}
}